3

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) 
8
  • 1
    Which JPA persistence provider do you use? What's the content of the persistence.xml file and what's the stack trace of the exception? Commented Nov 1, 2011 at 8:56
  • @JB Nizet: The stacktrace only says the above message. But even if I put illegal characters in my .xml file, I do not get an (other) error message. So I really want to know whether the application finds and reads my persistence.xml file or not. Commented Nov 1, 2011 at 9:36
  • The complete stack trace would help diagnosing this. But if you don't want to be helped, you're free not to answer. Are you sure the META-INF folder with the persistence.xml is in the classpath? Commented Nov 1, 2011 at 9:45
  • 1
    I think the problem is rather that your application doesn't find the jpa implementation (hibernate, eclipselink) than the file persistence.xml. Put the term No Persistence provider for EntityManager into the SO search box. There are a lot of similar questions. Commented Nov 1, 2011 at 11:02
  • 1
    Additional to those above, "<project>/src/META-INF/persistence.xml" has no bearing on what is in the CLASSPATH. Your invocation of your app defines what is in the CLASSPATH, and "/META-INF/persistence.xml" is the only place it will look for it at runtime. As per the JPA spec! Commented Nov 1, 2011 at 11:51

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.