1
저는 JDO 임베디드 엔터티를 사용하고 있습니다. this tutorial에 의해 부모와 자식 개체가 잘 설정되어 있습니다. 내 문제는 내가 자식 엔티티가 지속하도록 변경하지 못하는 것입니다. 여기 내 두 클래스는 다음과 같습니다JDO 임베디드 엔터티 필드 업데이트
는부모 :
는@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class TestEntity {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent
private String name;
@Persistent
@Embedded
private TestEntitySub sub;
public TestEntitySub getSub() {
return sub;
}
public void setSub(TestEntitySub sub) {
this.sub = sub;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
아이 :
@PersistenceCapable
@EmbeddedOnly
public class TestEntitySub {
@Persistent
private String state;
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
}
코드 수정 :
PersistenceManager pm = PMF.get().getPersistenceManager();
TestEntity test = pm.getObjectById(TestEntity.class, 75L); //object has id=75
test.getSub().setState("New State");
pm.makePersistent(test);
pm.close();
를 코드는 오류없이 실행되지만 데이터 저장소없이 보여줍니다 변경. 부모 개체의 자식 필드를 다시 설정하는 등 자식 개체를 유지하는 다양한 조합을 시도했지만 효과가 없습니다. 아이의 state
대신 부모의 name
을 수정하면 잘 작동합니다. 그렇다면 어떻게 자녀의 필드를 수정합니까?