views:

2525

answers:

7

I'm trying to load test data into a test DB during a maven build for integration testing. persistence.xml is being copied to target/test-classes/META-INF/ correctly, but I get this exception when the test is run.

javax.persistence.PersistenceException: No Persistence provider for EntityManager named aimDatabase

It looks like it's not finding or loading persistence.xml.

A: 

In what phase is the file being copied? Is it before the test phase?

sal
process-test-resources, which does precedes test
sblundy
+1  A: 

If this is on windows, you can use sysinternal's procmon to find out if it's checking the right path.

Just filter by path -> contains -> persistence.xml. Procmon will pick up any attempts to open a file named persistenc.xml, and you can check to see the path or paths that get tried.

See here for more detail on procmon: http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx

kbaribeau
+2  A: 

I had the same problem and it wasn't that it couldn't find the persistence.xml file, but that it couldn't find the provider specified in the XML.

Ensure that you have the correct JPA provider dependancies and the correct provider definition in your xml file.

ie. <provider>oracle.toplink.essentials.PersistenceProvider</provider>

With maven, I had to install the 2 toplink-essentials jars locally as there were no public repositories that held the dependancies.

stevemac
+1  A: 

Hi,

we got the same problem, does some tweaking on the project and finaly find following problem (more clear error description): at oracle.toplink.essentials.ejb.cmp3.persistence. PersistenceUnitProcessor.computePURootURL(PersistenceUnitProcessor.java:248)

With that information we recalled a primary rule: NO WHITE SPACES IN PATH NAMES!!!

Try this. Works for us smile. Maybe some day this will be fixed.

Hope this works for you. Good luck.

+1  A: 

I'm using Maven2, and I had forgotten to add this dependency in my pom.xml file:

 <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-entitymanager</artifactId>
   <version>3.4.0.GA</version>
 </dependency>
very good! my mistake also:) Thanks
artaxerxe
A: 

Just solved the same problem with a Maven/Eclipse based JPA project.

I had my META-INF directory under src/main/java with the concequence that it was not copied to the target directory before the test phase.

Moving this directory to src/main/resources solved the problem and ensured that the META-INF/persistence.xml file was present in target/classes when the tests were run.

I think that the JPA facet put my META-INF/persistence.xml file in src/main/java, which turned out to be the root of my problem.

jhumble
A: 

Is your persistence.xml located in scr/test/resources? Cause I was facing similar problems.

Everything is working fine as long as my persistence.xml is located in src/main/resources.

If I move persistence.xml to src/test/resources nothing works anymore.

The only helpful but sad answer is here: http://jira.codehaus.org/browse/SUREFIRE-427

Seems like it is not possible right now for unclear reasons. :-(

Nils Schmidt