Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EclipseLink JPA - location of persistence.xml

I am using JPA for a java class and having trouble putting the persistence XML file where it should be.

The IDE i am using is Eclipse Helios. Eclipselink jar files are downloaded and added to my JRE System Library and all. I wrote up the persistence.xml with the tag after getting the following error :

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named customers

Provider tag:

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

The program still doesn't run so i am wondering where should I place persistence.xml (i.e src/main/resources, or lib/META-INF... etc )

like image 711
neid Avatar asked Nov 26 '11 04:11

neid


People also ask

Where should persistence xml be located?

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.

In which location of JPA project does persistence xml?

The persistence. xml file is a standard configuration file in JPA. It has to be included in the META-INF directory inside the JAR file that contains the entity beans.

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.


2 Answers

JPA persistence XML file location

Traditionally, the persistence.xml is located in a META-INF folder that needs to reside in the root of the Java classpath. If you’re using Maven, you can store it in the resources folder, like this:

src/main/resources/META-INF/persistence.xml
like image 118
Vlad Mihalcea Avatar answered Nov 11 '22 15:11

Vlad Mihalcea


persistence.xml should be put inside an directory called META-INF under the root of the classpath .

Right click your project in eclipse ==> Properties ==> Java Build Path . Suppose you configure one of the build paths to be /src/main/resources , then you should put the persistence.xml at /src/main/resources/META-INF/persistence.xml

like image 21
Ken Chan Avatar answered Nov 11 '22 13:11

Ken Chan