Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where does Persistence.createEntityManagerFactory() look for the persistence unit?

I am using eclipse. I am trying to debug a failure to find the persistence unit that is indeed located in the directory structure of my eclipse project.

Where does EntityManagerFactory javax.persistence.Persistence.createEntityManagerFactory(String persistenceUnitName, Map properties) look for the persistence unit?

When I ask where it looks, I mean all the possible resources that could get searched, including eclipse configurations, properties in persistence.xml if the file is found, resources searched by included JARs, etc. To explore how this works, I am executing a test program by right clicking on a Main.java class located in the root (src/main/java) of an eclipse project.

The answer might help me figure out how to configure the eclipse project so that EntityManagerFactory javax.persistence.Persistence.createEntityManagerFactory(String persistenceUnitName, Map properties) can find the persistence unit.

like image 224
CodeMed Avatar asked Oct 14 '14 18:10

CodeMed


1 Answers

It searches your persistence.xml, located inside your META-INF dir. This folder has to be at the same level as your root package.

In a maven project, the folder would be in /src/main/resources/META-INF/persistence.xml

like image 50
mendieta Avatar answered Oct 22 '22 07:10

mendieta