我正在使用Google AppEngine和Java。当我使用一些数据存储功能,我收到一条错误消息:AppEngine数据存储区:“带ID的对象...由不同的对象管理器管理”
Object with id "[email protected]" is managed by a different Object Manager
我不知道这意味着什么或如何解决它或在哪里寻找这个错误文档。谁能帮我?我正在使用的代码是:
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class School {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private String shortname;
@Persistent
private String fullname;
@Persistent
@Order(extensions = @Extension(vendorName="datanucleus", key="list-ordering", value="code asc"))
private List<Teacher> Teachers;
...
public Teacher FindOrCreateTeacher(String code)
{
// Can we find the teacher without any database code?
Teacher newTeacher = FindTeacher(code);
if (newTeacher != null)
return newTeacher;
// Create the teacher:
PersistenceManager pm = PMF.get().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
for (Teacher teacher : Teachers) {
if (teacher.getCode() == code) {
tx.rollback();
return teacher;
}
}
newTeacher = new Teacher(code);
Teachers.add(newTeacher);
pm.makePersistent(newTeacher);
pm.makePersistent(Teachers);
tx.commit();
} finally {
tx.commit();
}
return newTeacher;
}
我相信“private List<Teacher> Teachers;
”是指“拥有一对多”的关系。
有趣的解释。 +1 – VonC 2009-10-07 17:36:42
您能否进一步向我解释PM实例的适合寿命?假设我正在编写一个Web应用程序。我应该在每个页面请求中打开并关闭它吗?或者在流程的整个过程中保持一个实例打开? (如果我提交了一个事务但不关闭PM,这是否意味着发生的最坏情况是内存泄漏?我的意思是,我的数据是安全的?) – 2009-10-09 06:51:17
这个过程需要多长时间?一个典型的网络系统将使用每个请求的PM。创建PM并不昂贵(创建PMF *是昂贵的)。如果使用txns,那么只要您还没有对该PM执行非事务性更新,就可以安全地让PM打开。 – DataNucleus 2009-10-09 07:10:35