No Persistence provider for EntityManager named

I have my persistence.xml with the same name using TopLink under the META-INF directory. Then, I have my code calling it with:

EntityManagerFactory emfdb = Persistence.createEntityManagerFactory("agisdb");

Yet, I got the following error message:

2009-07-21 09:22:41,018 [main] ERROR - No Persistence provider for EntityManager named agisdb
javax.persistence.PersistenceException: No Persistence provider for EntityManager named agisdb
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)

Here is the persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
    <persistence-unit name="agisdb">
        <class>com.agis.livedb.domain.AddressEntity</class>
        <class>com.agis.livedb.domain.TrafficCameraEntity</class>
        <class>com.agis.livedb.domain.TrafficPhotoEntity</class>
        <class>com.agis.livedb.domain.TrafficReportEntity</class>
        <properties>
            <property name="toplink.jdbc.url" value="jdbc:mysql://localhost:3306/agisdb"/>
            <property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="toplink.jdbc.user" value="root"/>
            <property name="toplink.jdbc.password" value="password"/>
        </properties>
    </persistence-unit>
</persistence>

It should have been in the classpath. Yet, I got the above error.


Solution 1:

Put the "hibernate-entitymanager.jar" in the classpath of application.
For newer versions, you should use "hibernate-core.jar" instead of the deprecated hibernate-entitymanager

If you are running through some IDE, like Eclipse: Project Properties -> Java Build Path -> Libraries.

Otherwise put it in the /lib of your application.

Solution 2:

After <persistence-unit name="agisdb">, define the persistence provider name:

<provider>org.hibernate.ejb.HibernatePersistence</provider>

Solution 3:

Make sure that the persistence.xml file is in the directory: <webroot>/WEB-INF/classes/META-INF

Solution 4:

Faced the same issue and couldn't find solution for quite a long time. In my case it helped to replace

<provider>org.hibernate.ejb.HibernatePersistence</provider>

with

<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

Took solution from here

Solution 5:

I needed this in my pom.xml file:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>4.2.6.Final</version>
</dependency>