当我尝试提交交易时,我得到了:
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;
.
.
}
答案 0 :(得分:1)
不是GAE专家,但是您的实体映射有一些明显的问题需要修复。
首先,将@ManyToOne
应用于列表是没有意义的(考虑一下,当您使用该注释时,您正在指示此实体的许多实体与映射的实体)。
其次,您尚未为嵌入的点集合指定实际的映射列。您必须在点类上定义从点到配置文件的映射,或使用连接表。下面是一个例子(非常粗略的伪代码):
@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表上的主键。