內關係我有三個@PC類:GAE數據存儲區不會存留資1: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;
}
}
我想要實現的是乙同時保持到C的引用被保存到相同的實體甲但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之前。
我在想什麼? TX
更新2:
的建議我已經明確地啓用事務:
Transaction tx = pm.currentTransaction();
try {
tx.begin();
pm.makePersistent(a);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
相同的異常被拋出W/O明確的事務做.makePersistent()時。然後我設置禁用全球跨在JDO配置TX選項:
<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 2013-04-30 10:27:52
我已經更新了這個問題。我知道我不明確地使用該交易,但根據也應該起作用的Google文檔。 – comeGetSome 2013-04-30 11:19:14
您向您的帖子中添加了「makePersistent」,但是...與*什麼對象*?當你打電話時,C的生命週期狀態是什麼?日誌告訴你所有這些東西 – DataNucleus 2013-04-30 12:32:00