Maven – javax.persistence.PersistenceException: No Persistence provider for EntityManager named xxx

jpamaven

Can't test a jpa/maven project. I have the error
"javax.persistence.PersistenceException: No Persistence provider for EntityManager named xxx"
when I run "mvn cleant test" from commandline. I have a Java SE project.

I have the persistence confiuration in 'src/test/resources/META-INF/persistence.xml'. And I also has the same for 'src/main/…'.
I can see the persistence.xml in 'target/classes/META-INF'. Only that is from the main, not from the test as I run the tests. This is not yet the problem, since both should work anyway.
Trying the JPA for the first time, but as I see, the files should be ok (location and content).

The persistence unit names should match also.

I'm using Eclipse (EE) with m2 and other necessary plugins, but running maven from commandline. I see no errors in the project.

// Update

Tried fixing the maven build as I noticed it should have the test classes and resources in 'target/test-classes'.
Changed the command to "mvn clean test-compile test"
Now the resources can be found from the correct place, but I still got the same error.

// update

For clarity here's the full persistence.xml

<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="xxx"
    transaction-type="RESOURCE_LOCAL">
    <provider>my.package.EntityManagerFactoryHelper</provider>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/db" />
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
        <property name="javax.persistence.jdbc.user" value="yyy" />
        <property name="javax.persistence.jdbc.password" value="zzz" />
        <property name="eclipselink.ddl-generation" value="DROP_AND_CREATE" />
    </properties>
</persistence-unit>

I took the helper example from other posts. Basically it just creates the emf using the 'xxx' persistence unit. Here's the helper class. http://pastebin.com/1GE6uMa1

Best Answer

Try to add < provider>org.hibernate.ejb.HibernatePersistence< /provider> inside tag

Related Topic