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

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

问题描述

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

  ... 
<属性>
<! - 扫描注释类 - >
< property name =hibernate.archive.autodetectionvalue =class/>
...

它似乎有效。然后该项目将作为JAR部署到两个不同的项目中。在其中之一中, persistence.xml 文件基本上与上面的文件相同,即使用 autodetection 功能休眠。然而,它似乎并没有工作(因为我认为它需要加载搜索罐子中的实体)。当我尝试在两个xml文件中手动列出所有实体时,一切正常。



编辑:它适用于 jar-file ,但仅限于jar的绝对路径。如果我正确地读了你的话,在它不起作用的情况下,这些实体是在不同的 JAR中比使用的persistence.xml,对吗?



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

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"/>
...

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.

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

解决方案

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?

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天全站免登陆