我对分离副本的理解是,它会创建对象的副本,以便您可以在没有PersistenceManager注意的情况下对其进行更改。JDO - 在将模型对象传递给视图之前,需要调用DetachCopy吗?
因为我接近用来传递模型对象视图之前我的PersistenceManager,我就不会沿着通过它我会之前调用像detachCopy或makeTransient什么?
我看着这些示例虽然叫它... 这是我看着例如,从http://code.google.com/appengine/docs/java/datastore/creatinggettinganddeletingdata.html:
public Employee getEmployee(User user) {
PersistenceManager pm = PMF.get().getPersistenceManager();
Employee employee, detached = null;
try {
employee = pm.getObjectById(Employee.class,
"[email protected]");
// If you're using transactions, you can call
// pm.setDetachAllOnCommit(true) before committing to automatically
// detach all objects without calls to detachCopy or detachCopyAll.
detached = pm.detachCopy(employee);
} finally {
pm.close();
}
return detached;
}
所以,如果我也不detachCopy或makeTransient它会抛出一个异常关闭PM之前? – Kyle 2010-02-10 19:39:43
究竟会抛出异常吗?如果你不makeTransient,或detachCopy或有PMF道具设置然后对象迁移到HOLLOW状态,按照JDO规范 – DataNucleus 2010-02-10 20:27:36
按照http://www.datanucleus.org/products/accessplatform/jdo/object_lifecycle.html – DataNucleus 2010-02-11 06:57:49