내의 1 개 관계 I 세 @PC 클래스가있다 : C 참조 채GAE 데이터 저장소가 소유 지속되지 않습니다 1 : 매립 JDO 클래스
@PersistenceCapable
class A {
@PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
private String id;
@Persistent @Embedded
private B b;
public void setB(B b){
this.b=b;
}
}
@PersistenceCapable @EmbeddedOnly
class B {
@Persistent
private String someInfo;
@Persistent
private C c;
public void setC(C c){
this.c=c;
}
}
@PersistenceCapable
class C {
@PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
private String id;
@Persistent
private String value;
public void setValue(String value){
this.value=value;
}
}
I가 B를 달성하고자하는이 같은 동일 엔티티에 유지된다 하지만 GAE 날, 나는에 다음과 같은 예외가 발생하지 않습니다 커밋 :
Detected attempt to establish A(1) as the parent of C(2) but the entity identified by C(2) has already been persisted without a parent. A parent cannot be established or changed once an object has been persisted.
를이 코드 :
A a = new A();
B b = new B();
C c = new C();
c.setValue("foo");
b.setC(c);
a.setB(b);
m.makePersistent(a);
또한 DatastoreViewer를 살펴보면 C가 지속되었음을 알 수 있습니다. 하지만 A가 없습니다. 이 경우 관련이없는 예외적 인 경우 트랜잭션을 명시 적으로 롤백하지 않기 때문에 발생할 수 있습니다. 그러나 C가 부모 A 앞에 쓰여 있음을 나타냅니다.
무엇이 누락 되었습니까? 텍사스
업데이트 2 :
내가 명시 적으로 트랜잭션을 사용하도록 설정 한 제안 :
Transaction tx = pm.currentTransaction();
try {
tx.begin();
pm.makePersistent(a);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
같은 예외가 명시 적 트랜잭션 오 승/.makePersistent()를 수행 할 때로 던져졌다.
<property name="datanucleus.appengine.datastoreEnableXGTransactions" value="false"/>
지금은 가능한 힌트 다른 예외를 얻을 :
cross-group transaction need to be explicitly specified, see
TransactionOptions.Builder.withXGfound both Element {
type: "A"
id: 1
}
and Element {
type: "C"
id: 2
}
데이터를 지속하려는 코드를 표시 하시겠습니까? – skirsch
질문을 업데이트했습니다. 나는 노골적으로 트랜잭션을 사용하지 않는다는 것을 안다. – comeGetSome
게시물에 'makePersistent'를 추가했는데 어떤 오브젝트가 *? 당신이 전화를 걸 때 C의 라이프 사이클 상태는 무엇입니까? 로그는 그 모든 것을 알려줍니다. – DataNucleus