java - Google App Engine - ID 为 ""的对象由不同的 JPA 管理

标签 java google-app-engine jpa

当我尝试提交交易时,我得到:

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/

相关文章:

java - Spring Webflow : How to change the destination of a transition in a child flow

java - 如何使用 Java Streams 从对象列表中获取 Set

google-app-engine - 在 Google App Engine 上部署时,将数据存储在静态字段中是否线程安全?

java - 执行 WS 操作后未调用 SoapHandler

Java 字符串比较/引用

python - 使用 google app engine 进行文件 I/O

java - 如何更改 Google 应用引擎上 Web 服务调用的默认超时?

java - 单表继承(使用 Ebean + Play! 框架)

jpa - Eclipselink JPA 在使用生成的主键插入 Derby 表时出错

javax.persistence.PersistenceException : org. hibernate.id.IdentifierGenerationException: