当我尝试提交交易时,我得到:
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
我的代码是:
@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;
.
.
}
- 如果我删除带有他注释的 m_points,一切正常。
- 我将 JPA 1.0 与 Google App Engine 结合使用
我做错了什么?
谢谢。
最佳答案
不是 GAE 专家,但您的实体映射存在一些明显的问题需要修复。
首先,将 @ManyToOne
应用于列表是没有意义的(想一想,您的意思是,当您使用该注释时,this实体与映射实体之一相关。
其次,您没有为嵌入的点集合指定实际的映射列。您必须在点类上定义从点到剖面的映射,或者使用连接表。下面是一个示例(非常粗糙的伪代码):
@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;
}
很明显,上面的示例假定在 MyPoint 表上有一个名为 profileId
的外键引用了 Profile 表上的主键。
关于java - Google App Engine - ID 为 ""的对象由不同的 JPA 管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11110826/