Roalt
Roalt

Reputation: 8450

determine location of persistence.xml

I'm trying to use jpa in a desktop application. I keep getting the error No Persistence provider for EntityManager named <unit> and I suspect that my persistence.xml cannot be located.

I've placed it in the <project>/src/META-INF/persistence.xml

I have the feeling that jpa cannot find this file, but I do not known how to troubleshoot.

How can I specify where the persistence.xml file is stored and how can I check if it is actually read?

Stacktrace:

javax.persistence.PersistenceException: No Persistence provider for EntityManager named myunit
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
    at myapplication.MyEntity.testAddEntity(HistoryAction.java:85)

Upvotes: 3

Views: 10073

Answers (2)

Matt Handy
Matt Handy

Reputation: 30025

I think the problem is rather that your application doesn't find the jpa implementation (hibernate, eclipselink) than the file persistence.xml.

See this related question and answers.

Upvotes: 3

Roalt
Roalt

Reputation: 8450

You get this error if the JPA cannot find a correct jpa implementation (e.g. hibernate, eclipselink).

Make sure you include the right .jar's to your build path that contain the JPA implementation you are using.

(Answer given in a comment by Matt Handy)

Upvotes: 1

Related Questions