Meaningless Drivel is fun!*
The moose likes Object Relational Mapping and the fly likes JPA: Can't find Persistence Provider Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA: Can Watch "JPA: Can New topic
Author

JPA: Can't find Persistence Provider

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
Edvins Reisons
Ranch Hand

Joined: Dec 11, 2006
Posts: 364
Have you tried to specify a <provider> element for your persistence unit?
Pierre Henry
Ranch Hand

Joined: Oct 01, 2003
Posts: 31
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


"A good method shouldn't bypass one screen long"<br />"genius is the knowledge left when one has forgotten everything"
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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

Joined: Oct 01, 2003
Posts: 31
Merrill,

Can you send a stack trace to see the origin of the problem?
Wally Hartshorn
Ranch Hand

Joined: Jan 30, 2003
Posts: 77
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.


Wally Hartshorn
kaan acar
Greenhorn

Joined: Apr 09, 2007
Posts: 1
I have exactly same problem. How could you solve your problem.
Thanks.
Neil Laurance
Ranch Hand

Joined: Jul 18, 2002
Posts: 183
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

Joined: Sep 30, 2012
Posts: 1
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
 
 
subject: JPA: Can't find Persistence Provider
 
Similar Threads
EJB3 2 client apps and 2 different databases
Problem in Standalone persistence
No Persistence provider for EntityManager
JPA - problem with persistence.xml
Please tell me I have a typo in my Persistence.xml