【发布时间】:2014-12-16 09:49:33
【问题描述】:
我有两个 ejb-jars 位于 [WAR]/WEB-INF/lib 的项目。两个 ejb-jars 都使用 JPA 并包含注释为 @Entity 的类。但是我在打包和部署方面遇到了问题(Glassfish 4)。如果我的两个 jar 都包含 persistence.xml,那么我会在 delpoyment 上得到以下异常
java.lang.RuntimeException: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [...] in the scope of the module called [...]. Please verify your application.
我已将 persistence.xml 放入 WAR/META-INF 并从 ejb-jar 中删除 persistence.xml。部署成功,但运行时出现异常
java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Problem compiling [SELECT ...].
[14, 18] The abstract schema type 'MyClass' is unknown.
MyClass 是来自 ejb-jar 之一的 @Entity 类。我认为这个 ejb-jar 中缺少persistence.xml 的问题。
最后我尝试将persistence.xml 放入 WAR 和 ejb-jars 中,但我又得到了
java.lang.RuntimeException: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [...] in the scope of the module called [...]. Please verify your application.
什么是放置persistence.xml 的合适位置以及打包此类应用程序的正确方法是什么?
【问题讨论】:
标签: jakarta-ee jpa war packaging persistence.xml