我對分離副本的理解是,它會創建對象的副本,以便您可以在沒有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