No Persistence provider for EntityManager named

Robert A Henru picture Robert A Henru · Jul 21, 2009 · Viewed 381.9k times · Source

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.

Answer

Ualter Jr. picture Ualter Jr. · Feb 25, 2011

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.