Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

persistence.xml not found during maven testing

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.

like image 536
sblundy Avatar asked Sep 16 '08 20:09

sblundy


People also ask

Where can I find persistence xml?

xml should be put in the EJB JAR's META-INF directory. If you package the persistence unit as a set of classes in a WAR file, persistence. xml should be located in the WAR file's WEB-INF/classes/META-INF directory.

Is persistence xml required for JPA?

xml configuration. You can use JPA with a very short, basic configuration. You only need a persistence element as the root element and a persistence-unit element with a name attribute.

Does spring boot need persistence xml?

Spring Boot will not search for or use a META-INF/persistence. xml by default. If you prefer to use a traditional persistence. xml , you need to define your own @Bean of type LocalEntityManagerFactoryBean (with an ID of 'entityManagerFactory') and set the persistence unit name there.

What is the purpose of the persistence xml file?

The persistence. xml configuration file is used to configure a given JPA Persistence Unit. The Persistence Unit defines all the metadata required to bootstrap an EntityManagerFactory , like entity mappings, data source, and transaction settings, as well as JPA provider configuration properties.


1 Answers

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

like image 51
Nils Schmidt Avatar answered Sep 23 '22 01:09

Nils Schmidt