By default autodetection works for entities in the same classpath item as persistence.xml
. It can be configured by <jar-file>
elements.
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
- enable resource filtering for src/test/resources
:
<project ...>
...
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
</build>
</project>
Though I'm not sure how to use it if your persistence.xml
is actually in src/test/META-INF
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…