【问题标题】:Google App Engine: JDO does the job, JPA does notGoogle App Engine:JDO 能胜任,JPA 不能
【发布时间】:2011-01-28 11:14:54
【问题描述】:

我已经使用 Jdo 和 Jpa 设置了一个项目。 我使用 Jpa Annotation 来声明我的实体。 然后我根据LocalTestHelper(来自 Google App Engine 文档)设置我的测试用例。 当我运行测试时, 拨打Jdo:PersistenceManagermakePersistent 完全可以; 对Jpa:EntityManagerpersist 的调用引发错误:

java.lang.IllegalArgumentException: Type ("org.seamoo.persistence.jpa.model.ExampleModel") is not that of an entity but needs to be for this operation
    at org.datanucleus.jpa.EntityManagerImpl.assertEntity(EntityManagerImpl.java:888)
    at org.datanucleus.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:385)
Caused by: org.datanucleus.exceptions.NoPersistenceInformationException: The class "org.seamoo.persistence.jpa.model.ExampleModel" is required to be persistable yet no Meta-Data/Annotations can be found for this class. Please check that the Meta-Data/annotations is defined in a valid file location.
    at org.datanucleus.ObjectManagerImpl.assertClassPersistable(ObjectManagerImpl.java:3894)
    at org.datanucleus.jpa.EntityManagerImpl.assertEntity(EntityManagerImpl.java:884)
    ... 27 more

怎么会这样呢? 以下是重现该问题的 Maven 项目的紧凑源代码的链接: 更新http://seamoo.com/jpa-bug-reproduce-compact.tar.gz

在父 pom 上执行 maven 测试目标,您会注意到来自 org.seamoo.persistence.jdo.JdoGenericDAOImplTest 的 3/4 测试通过了,而来自 org.seamoo.persistence.jpa.JpaGenericDAOImplTest 的所有测试都失败了。

【问题讨论】:

    标签: google-app-engine jpa maven


    【解决方案1】:

    所以你要么没有增强你的模型类,要么没有为它们提供持久性元数据(XML、注释)(在运行时)。日志告诉您充足的信息。而且我真的不认为向人们展示一些 tgz 和 3 个单独的项目并期望他们找到您所指的特定课程可以称为“他们的时间的最佳使用”。将其缩减为实际的类、它的元数据和一个示例 Main

    【讨论】:

    • 您好,很抱歉给您带来不便。我已经更新了我的源代码并删除了所有超出问题范围的代码。顺便说一句,我很好奇的是:我为我的实体使用了 JPA 注释,但是 JDO API 可以很好地处理这些实体,而 JPA API 不能。正如您在源代码中看到的,ExampleModel 由 maven datanucleus 插件增强。即使我错过了任何必需的数据,为什么 JDO 有效?
    • JDO 工作(使用 JDO 或 JPA 输入),JPA 工作(使用 JDO 或 JPA 输入)。 GAE/J 论坛上所有使用 JPA 的人都不会错:-P。测试用例被“清理”了吗?我希望有一个模型类和一个主要的persistence.xml。这就是它所需要的。不,我看不到任何关于增强的内容;你的日志告诉你。加强你的课程? (对于 JPA?)。运行时,CLASSPATH 中有什么?日志(DEBUG 级别)会告诉您所有这些,因此查看它会很有意义。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-01
    • 2021-12-25
    • 2011-06-19
    • 2011-01-02
    • 1970-01-01
    • 2016-12-16
    • 1970-01-01
    相关资源
    最近更新 更多