在 maven-verify 中没有自动检测 JPA 实体 [英] No autodetection of JPA Entities in maven-verify
问题描述
如果我将 persistence.xml 放在 src/test/META-INF 文件夹中,则自动检测实体不适用于 maven-verify.当persistence.xml 位于src/main/META-INF 文件夹中时,它可以工作.
If I put the persistence.xml in the src/test/META-INF folder, autodetection the Entities does not work with maven-verify. When the persistence.xml is located in the src/main/META-INF folder it works.
在 Eclipse 中运行测试适用于两种情况.
Running the tests in eclipse works in both cases.
当persistence.xml 位于src/test 文件夹中时,有没有办法让自动检测为maven-verify 工作?
Is there a way to get autodetection to work for maven-verify when the persistence.xml is located in the src/test Folder?
持久性.xml:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="Unit" transaction-type="RESOURCE_LOCAL">
<properties>
<!-- Scan for annotated classes and Hibernate mapping XML files -->
<property name="hibernate.archive.autodetection" value="class" />
</properties>
</persistence-unit>
</persistence>
推荐答案
默认情况下,自动检测适用于与 persistence.xml
位于同一类路径项中的实体.它可以通过
元素进行配置.
By default autodetection works for entities in the same classpath item as persistence.xml
. It can be configured by <jar-file>
elements.
要在 persistence.xml
在 src/test/resources/META-INF
中时启用正确的自动检测,我使用以下技巧:
To enable correct autodetection when persistence.xml
is in src/test/resources/META-INF
I use the following trick:
persistence.xml
:
<persistence ...>
<persistence-unit ...>
<jar-file>${project.build.outputDirectory}</jar-file>
...
</persistence-unit>
</persistence>
pom.xml
- 为 src/test/resources
启用资源过滤:
pom.xml
- enable resource filtering for src/test/resources
:
<project ...>
...
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
</build>
</project>
如果您的 persistence.xml
实际上在 src/test/META-INF
中,我不确定如何使用它.
Though I'm not sure how to use it if your persistence.xml
is actually in src/test/META-INF
.
这篇关于在 maven-verify 中没有自动检测 JPA 实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!