【问题标题】:The id of an object retrieved by JPA is missing缺少 JPA 检索到的对象的 id
【发布时间】:2011-12-02 22:11:56
【问题描述】:

我有一个带有整数 id 字段的简单对象,如下所示:

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(unique = true, nullable = false)
private int id;

对象可以正确地持久化到数据库中。但是,当通过以下方式从数据库中检索对象时:

EntityManagerFactory emFactory = Persistence.createEntityManagerFactory("MyService");
EntityManager entityManager = emFactory.createEntityManager();
MyObject myObject = entityManager.find(MyObject.class, 1);
entityManager.close();

检索到的对象的 id 字段始终为零,但所有其他字段的值都被正确检索。

如果我从代码中删除@Id 注释,则可以像所有其他字段一样正确检索 id 字段的值。

我在 MS SQL Server 2008 中使用 OpenJPA。MS sqljdbc 驱动程序和 JTDS 驱动程序都经过测试。

【问题讨论】:

    标签: java jpa openjpa


    【解决方案1】:

    这是使用 eclipse 插件增强时的known bug。我强烈建议您使用另一种构建时间的方法enhancement。随时向 OpenJPA 用户邮件列表发布其他问题。

    【讨论】:

    • 谢谢你,瑞克。答案很有帮助。
    猜你喜欢
    • 2019-10-05
    • 1970-01-01
    • 1970-01-01
    • 2017-03-31
    • 2017-04-28
    • 1970-01-01
    • 2013-11-15
    • 2015-12-22
    • 2019-04-02
    相关资源
    最近更新 更多