Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA: Can't find Persistence Provider

 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

I'm running this from Eclipse.
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried to specify a <provider> element for your persistence unit?
 
Pierre Henry
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Merrill,

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.

That'all
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pierre Henry
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Merrill,

Can you send a stack trace to see the origin of the problem?
 
Wally Hartshorn
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
kaan acar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have exactly same problem. How could you solve your problem.
Thanks.
 
Neil Laurance
Ranch Hand
Posts: 183
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
mohammad bany yaseen
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All ,


i try add a java project to use JPA persistance (not dynamic web application) i add the jar file for the entity manager but still get the same problem
here is my configrations and class files


this is the persistence.xml file under the "src" directory



and the entity class manager :




and the DAO book class




and about the Book Entity class



when i run the following test code as java application i get the same error :


best regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic