0
votes

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

2
See this related SO questionRaghuram

2 Answers

0
votes

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

0
votes

The provider has to be:

     <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

Else the table creation fails, even that there is no errors when creating the tables from the entities.

Spent about 2 days resolving this, since I thought I was pointed the right direction by the given hint and didn't check the provider then.

The provider has to be according to the eclipselink, as you could spot it in the configuration of the 'persistence.xml'.

But I failed to say it explicitly. Didn't know it would matter that much and it even succeeded with the table creation once. Not really sure what I had for the provider then, but it failed subsequently (after changes made to the table). Probably there should had been other configurations by the provider.