Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No autodetection of JPA Entities in maven-verify

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.

Running the tests in eclipse works in both cases.

Is there a way to get autodetection to work for maven-verify when the persistence.xml is located in the src/test Folder?

persistence.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>
like image 455
Dominik Avatar asked Feb 03 '11 11:02

Dominik


1 Answers

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.

like image 176
axtavt Avatar answered Oct 27 '22 15:10

axtavt