【问题标题】:Google App Engine. JPA. @ManyToOne causes org.datanucleus.store.appengine.DatastoreRelationFieldManager$ChildWithoutParentException谷歌应用引擎。 JPA。 @ManyToOne 导致 org.datanucleus.store.appengine.DatastoreRelationFieldManager$ChildWithoutParentException
【发布时间】:2013-02-09 12:23:05
【问题描述】:
@Entity
public class Group
{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Key id;
}


@Entity
public class User
{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Key id;

    @ManyToOne(fetch = FetchType.LAZY)
    private Group group;
}

后面的代码:

EntityManager entityManager = EntityManagerFactoryHolder.getEntityManagerFactory().createEntityManager();
Group group = new Group();
entityManager.persist(group);
User user = new User();
user.setGroup(group);
entityManager.persist(user);
entityManager.close();

我收到以下错误

检测到尝试将 User(28) 建立为 Group(27) 的父级,但是 Group(27) 所标识的实体已经被持久化了 家长。对象一旦创建就无法建立或更改父级 一直坚持。 org.datanucleus.store.appengine.DatastoreRelationFieldManager$ChildWithoutParentException: 检测到尝试将 User(28) 建立为 Group(27) 的父级,但 Group(27) 所标识的实体已经被持久化了 家长。对象一旦创建就无法建立或更改父级 已被持久化。

【问题讨论】:

    标签: google-app-engine jpa datanucleus


    【解决方案1】:

    似乎这只适用于反向关联。将 @OneToMany 设置为 Group 对象,现在可以使用了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-06
      • 1970-01-01
      • 2012-02-08
      • 2011-12-16
      • 1970-01-01
      相关资源
      最近更新 更多