EclipseLink JPA - location of persistence.xml
Asked Answered
T

2

10

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 )

Tenney answered 26/11, 2011 at 4:0 Comment(1)
I find it unexpected that it's in META-INF rather than WEB-INF when you consider the xml file for spring beans is in WEB-INF.Tautology
E
24

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

Epiphragm answered 26/11, 2011 at 8:10 Comment(2)
how can i set a customized path for persistence.xml ?Carmon
@Carmon - I'm sure you've found the answer now but just in case anyone else is wondering: https://mcmap.net/q/1161549/-application-context-spring-configuration-file-not-foundTautology
C
1

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
Chirpy answered 10/3, 2020 at 16:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.