Google App Engine - ID为“&”的对象由不同的JPA管理 [英] Google App Engine - Object with id "" is managed by a different - JPA

查看:102
本文介绍了Google App Engine - ID为“&”的对象由不同的JPA管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试提交事务时,我得到:

  javax.persistence.RollbackException:事务未能提交
javax.persistence.PersistenceException:id为的对象由不同的
管理org.datanucleus.exceptions.NucleusUserException:具有id的对象由不同的Object ManagerObject Manager管理

我的代码是:

  @Entity 
public class Profile实现Serializable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long profileId;

private String m_Name;
private String m_Email;
private String m_Password;

@ManyToOne()
私人列表< MyPoint> m_points = null;


}

@Entity
public class MyPoint实现Serializable
{
private static final long serialVersionUID = 1L;
@Id
private int pointId;

private int m_LatitudeE6;
private int m_LongitudeE6;


}




  • 如果我用他的注释删除m_points一切正常。

  • 我使用JPA 1.0和Google App Engine

    我在做什么错?

    谢谢。
  • >

解决方案

不是GAE专家,但是您的实体映射有一些明显的问题需要固定。

首先,将 @ManyToOne 应用于列表是没有意义的(考虑一下,当你使用该注释时,这个实体与许多映射的实体相关联。)

其次,您还没有为嵌入的点集指定实际的映射列。您必须在点类上定义从点到轮廓的映射,或者使用连接表。下面是一个例子(非常粗略的伪代码):

  @Entity 
public class Profile实现Serializable {

@OneToMany(mappedBy =profile)
私人列表< MyPoint> m_points = null;
}

@Entity
public class MyPoint实现Serializable {

@ManyToOne
@JoinColumn(name =profileId)
私人档案资料;
}

很明显,上面的例子假设有一个名为<$ MyPoint表上的c $ c> profileId 引用了Profile表上的主键。


When I'm trying to commit Transaction I'm getting:

javax.persistence.RollbackException: Transaction failed to commit
javax.persistence.PersistenceException: Object with id "" is managed by a different 
org.datanucleus.exceptions.NucleusUserException: Object with id "" is managed by a different Object ManagerObject Manager

My Code is:

@Entity
public class Profile implements Serializable
{
    private static final long serialVersionUID = 1L;
    @Id     
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    private Long profileId;

    private String m_Name;    
    private String m_Email;
    private String m_Password;  

    @ManyToOne()
    private List<MyPoint> m_points = null;
    .
    .
}

@Entity
public class MyPoint  implements Serializable 
{
    private static final long serialVersionUID = 1L;    
    @Id
    private int pointId;

    private int m_LatitudeE6;
    private int m_LongitudeE6;
    .
    .
}

  • If I'm deleting m_points with his annotations everything works fine.
  • I'm using JPA 1.0 with Google App Engine
    What am I doing wrong?
    Thanks.

解决方案

Not a GAE expert, but there are some obvious things wrong with your entity mappings that need to be fixed.

First, it makes no sense to apply a @ManyToOne to a list (think about it, your are indicating, when you use that annotation, that many of this entity relate to one of the mapped entity).

Second, you have not specified the actual mapping columns for the embedded collection of points. You must either define the mapping from point to profile on the point class, or use a join table. Below is an example (very rough pseudo-code):

@Entity
public class Profile implements Serializable { 

    @OneToMany(mappedBy = "profile")
    private List<MyPoint> m_points = null;
}

@Entity
public class MyPoint implements Serializable {

    @ManyToOne
    @JoinColumn(name = "profileId")
    private Profile profile;
}

Quite obviously, the above example presumes that there is a foreign key named profileId on the MyPoint table that references the primary key on the Profile table.

这篇关于Google App Engine - ID为“&”的对象由不同的JPA管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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