JDO - 在将模型对象传递给视图之前,我是否需要对其调用 DetachCopy?
我对分离复制的理解是,它会创建对象的副本,以便您可以在 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,
"[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;
}
My understanding of detach copy is that it makes a copy of your object so that you can make changes to it without the PersistenceManager noticing.
Since I close my PersistenceManager before passing the model object to the view to be used, I wouldn't have to call anything like detachCopy or makeTransient before passing it along would I?
The examples I looked at do call it though...
This is the example I looked at from 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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 PMF 属性自动分离对象,或者手动分离它们的副本,如示例所示。现在问题是什么?
You can have objects detached automatically using the PMF prop, or detach copies of them manually, as the example says. Now what was the question?
来自 http://db.apache.org/jdo/attach_detach.html
From http://db.apache.org/jdo/attach_detach.html