将实体移入外部jar包后未映射
在我的 Java/Seam/JbossAS 应用程序中,我决定外部化我的模型类(休眠实体)并将它们移动到另一个项目中。该项目生成 model.jar,然后由主应用程序使用。 model.jar 依赖关系由 Ivy 解决。 使用 Ant 构建主应用程序可以毫无问题。然后我手动将 model.jar 复制到“mainapp.ear/lib”目录中。之后我部署应用程序,没有任何问题(尽管我注意到没有关于找到的映射的日志信息)。但是当我想登录时,我得到了异常:
javax.el.ELException: javax.ejb.EJBTransactionRolledbackException:
org.hibernate.hql.ast.QuerySyntaxException: AppUser is not
mapped [select u from AppUser u where u.userName = :usernamePar]
同时没有代码更改,只是将一些类外部化到 jar 中。这是否意味着我在编译主应用程序时需要模型类的源代码?
In my Java/Seam/JbossAS app, I decided to externalize my Model classes (hibernate entities) and moved them into another project. The project produces model.jar, which is then used by the main app. The model.jar dependency is resolved by Ivy.
Building the main app with Ant works without problems. Then I copy manually the model.jar into 'mainapp.ear/lib' directory. Afterwards I deploy the app and there are no problems (although I notice that there are is no log info about found mappings). But when I want to login, I get the exception:
javax.el.ELException: javax.ejb.EJBTransactionRolledbackException:
org.hibernate.hql.ast.QuerySyntaxException: AppUser is not
mapped [select u from AppUser u where u.userName = :usernamePar]
There were no code changes in the meantime, just externalizing some of the classes into a jar. Does this mean, that I need the source code of the Model classes when compiling the main app?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
EntityManagerFactory
专为仅扫描包含/META-INF/persistence.xml
文件的 jar 中的实体而构建。为了扫描其他 jar,您必须使用
:请参阅 Hibernate 文档。
The
EntityManagerFactory
is built for scanning entities only from the jar that has a/META-INF/persistence.xml
file into.In order to scan other jars you have to use
<jar-file>
:See 2.2.1 Packaging in Hibernate doc.
还要检查您的休眠映射是否正确放置在休眠配置文件中。请注意,hibernate 映射资源或类与 hibernate.cfg.xml 文件的位置相关。
Also check if your hibernate mappings are correctly placed wrt hibernate config file. Note that hibernate mapping resources or classes are relative to the location of hibernate.cfg.xml file.