AppEngine 数据存储:“带有 id 的对象...由不同的对象管理器管理"; [英] AppEngine datastore: "Object with id ... is managed by a different Object Manager"

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

问题描述

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

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

我认为private ListTeachers;"是指拥有,一对多"的关系.

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

推荐答案

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

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);

由于您没有定义消息的来源,因此无法多说.DataNucleus 日志条目会告诉您的方式远不止这些.

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.

关闭 PM 始终是必不可少的事情(除非您想要资源泄漏)

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

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

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆