I'm working through the examples in the book "Java Persistence with Hibernate". I've created a JPA probject as a Java project in Eclipse with all the necessary dependencies set up.
According to the book, one should be able to place a persistence.xml file in the META-INF directory of the classes root directory and have the Persistence class find it when it's time to build the EntityManager. However, this just does not seem to work for me. Any ideas? Below is my code:
persistence.xml in META-INF
When I try to exeute the statement:
I get the error: Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named helloworld
In the persistence schema definition, you have the <provider> element which indicates what persitence provider to use the DAO. For instance:
to tell it you use Hibernate as the persistence framework.
"A good method shouldn't bypass one screen long"<br />"genius is the knowledge left when one has forgotten everything"
Joined: Feb 15, 2005
Thanks for your replies. I did try adding the <provider> stanza, but unfortunately, it didn't help. This problem appears to have something to do with the way applications are run inside Eclipse, because when I download the solution code and run it from an ANT task, it works fine.
Joined: Oct 01, 2003
Can you send a stack trace to see the origin of the problem?
Originally posted by Merrill Higginson: Thanks for your replies. I did try adding the <provider> stanza, but unfortunately, it didn't help. This problem appears to have something to do with the way applications are run inside Eclipse, because when I download the solution code and run it from an ANT task, it works fine.
To run it from within Eclipse, you might have to place the META-INF/persistence.xml file at the root of the source (or src) directory.
I had this as well. It is because I had forgotten to place the hibernate-entitymanager.jar into my lib directory. Then when Persistence tries to find any persistence-providers on the classpath, it was not finding any at all. Cheers, Neil