我使用GAE 1.7.0 w/JDO(DataNucleus)。 當我使用集合屬性持久保存類時,不會從數據存儲中刪除已刪除的集合成員。我從分離的副本中刪除集合成員。新成員正確添加,現有的成員沒有刪除,導致我的收藏只增長。JDO(DataNucleus)收集成員不會被刪除
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class Parent{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent(defaultFetchGroup="true", dependentElement="true")
private List<Child> children = new ArrayList<Child>(0);
}
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class Child implements Serializable {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
private String id;
@Persistent
@Extension(vendorName="datanucleus", key="gae.parent-pk", value="true")
private String parentId;
....
}
...
parent = pm.detachCopy(resultFromQuery);
// parent looks correct in dubugger: all children are fetched (and detached)
....
parent.getChildren().clear();
parent.getChildren().addAll(newChildren);
for (Child child: parent.getChildren())
child.setParentId(KeyFactory.createKeyString("Parent", parent.getId()));
// parent looks good in the debugger: old children were removed and new ones added
...
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
pm.currentTransaction().begin();
pm.makePersistent(parent);
pm.currentTransaction().commit();
} catch (Exception e) {
} finally {
if (pm.currentTransaction().isActive())
pm.currentTransaction().rollback();
if (!pm.isClosed())
pm.close();
}
// problem in datastore: new children were created, old ones not removed
我注意到,如果我做的查詢,刪除,堅持一個交易(不拆卸的對象),那麼問題就解決了。這是一個好的臨時解決方法,但我仍然想對分離的對象進行更新。
同樣的問題DataNucleus artifactId datanucleus-core 3.1.3和Google App Engine 1.9.21。 – CoolDude