我对分离副本的理解是它会复制您的对象,以便您可以在没有 PersistenceManager 注意到的情况下对其进行更改。
因为我在将模型对象传递给要使用的视图之前关闭了我的 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,
"Alfred.Smith@example.com");
// 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;
}