本文介绍了AppEngine数据存储:“具有ID的对象...由不同的对象管理器管理”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google AppEngine和Java。当我使用某些数据存储功能时,我收到一条错误消息:

$ pre $ id为edvaltt.Teacher@64064b的对象是由不同的对象管理器管理

我不知道这意味着什么或如何解决它或在哪里查找有关此错误的文档。谁能帮我?我使用的代码是:

  @PersistenceCapable(identityType = IdentityType.APPLICATION)
public class School {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private String shortname;

@Persistent
私人字符串全名;

@Persistent
@Order(extensions = @Extension(vendorName =datanucleus,key =list-ordering,value =code asc))
private List< ;教师>教师;

...

公共教师FindOrCreateTeacher(字符串代码)
{
//我们可以找到没有任何数据库代码的老师吗?
Teacher newTeacher = FindTeacher(code);
if(newTeacher!= null)
return newTeacher;

//创建教师:
PersistenceManager pm = PMF.get()。getPersistenceManager();
Transaction tx = pm.currentTransaction();
尝试{
tx.begin();
for(Teacher teacher:Teachers){
if(teacher.getCode()== code){
tx.rollback();
回报老师;
}
}
newTeacher = new Teacher(code);
Teachers.add(newTeacher);
pm.makePersistent(newTeacher);
pm.makePersistent(教师);
tx.commit();
} finally {
tx.commit();
}
返回newTeacher;
}

我相信私人列表<教师>教师; 指的是拥有的,一对多的关系。

解决方案

只能由一个PersistenceManager管理。在DataNucleus中,这由ObjectManager在内部支持。该消息表示您正尝试将由一个PM管理的对象与另一个PM关联。您可以通过打印每个(持久性)对象的PM来轻松地进行调试

  JDOHelper.getPersistenceManager(obj); 

由于您没有定义消息来自何处,因此不能多说。 DataNucleus日志条目会告诉你更多的方式。



关闭PM始终是一件重要的事情(除非你想要资源泄漏)。 b $ b

I'm using the Google AppEngine, with Java. When I use some datastore features, I'm getting an error message:

Object with id "edvaltt.Teacher@64064b" is managed by a different Object Manager

I don't know what this means or how to fix it or where to look for documentation on this error. Can anyone help me? The code I'm using is:

@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;
}

I believe that "private List<Teacher> Teachers;" refers to an "owned, one to many" relationship.

解决方案

A persistent object can only be "managed" by one PersistenceManager. In DataNucleus this is backed internally by an "ObjectManager". The message says that you are trying to associate an object managed by one PM with a different PM. You can easily debug that by printing out the PM for each (persistent) object

JDOHelper.getPersistenceManager(obj);

Since you don't define where the message comes from, not much more can be said. The DataNucleus log entries would tell you way way more than that.

Closing the PM is always an essential thing to do (unless you want resource leaks)

这篇关于AppEngine数据存储:“具有ID的对象...由不同的对象管理器管理”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 20:36