persistence.xml not found during maven testing

人走茶凉 提交于 2019-12-05 20:22:54

问题


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.


回答1:


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.




回答2:


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> 



回答3:


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




回答4:


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.




回答5:


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. :-(




回答6:


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.



来源:https://stackoverflow.com/questions/76591/persistence-xml-not-found-during-maven-testing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!