从 jar 自动检测 Hibernate 中的类 [英] Autodetect classes in Hibernate from jar

查看:14
本文介绍了从 jar 自动检测 Hibernate 中的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个实体的 JavaEE 项目,其中包含以下 persistence.xml 文件:

I have a JavaEE project with several entities with the following persistence.xml file:

...
<properties>
    <!-- Scan for annotated classes -->
    <property name="hibernate.archive.autodetection" value="class"/>
...

它似乎有效.然后将该项目作为 JAR 部署到两个不同的项目.其中一个persistence.xml文件与上面的基本相同,即使用了Hibernate的autodetection特性.但是,它似乎不起作用(因为我认为它需要加载搜索 jar 中的实体).当我尝试手动列出两个 xml 文件中的所有实体时,一切正常.

And it seems to work. The project is then deployed as a JAR to two different projects. In one them, the persistence.xml file is basically the same as the one above, i.e. uses the autodetection feature of Hibernate. However, it does not seem to work (because I think it needs to load search for the entities in a jar). When I tried manually listing all the entities in both xml files, everything works correctly.

它适用于 jar-file,但仅适用于 jar 的绝对路径.对于团队项目来说毫无用处.

It works with jar-file but only with the absolute path to the jar. Pretty useless for a team project.

推荐答案

如果我没看错的话,在它不起作用的情况下,实体位于与持久性不同的 JAR 中.使用的 xml,对吗?

If I read you correctly, in the case where it does not work, the entities are in a different JAR than the persistence.xml that's used, right?

我认为你是对的,这就是问题所在.您需要使用 jar-file 元素告诉 Hibernate 要扫描哪些 JAR.请参阅 Hibernate 文档中的解释和示例 这里

I think you're correct that's the problem. You need to tell Hibernate which JAR(s) to scan using the jar-file element. See the explanation and examples in the Hibernate docs here

这篇关于从 jar 自动检测 Hibernate 中的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆