No autodetection of JPA Entities in maven-verify

build, java, jpa, maven

Solution

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`.

Problem

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> ```

Original source