views:

7844

answers:

6

I have my persistence.xml with the same name, using toplink, under 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... Really appreciate any help... Thanks

+1  A: 

You may have this sorted already but if not, after <persistence-unit name="agisdb"> I think you need to add <provider>org.hibernate.ejb.HibernatePersistence</provider> (or whatever persistence provider you want to use). Hope that helps!

+2  A: 

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

A: 

I have the same problem and I haven't sort it out yet. Do you have a solution for this to share with you????

dejaninic
A: 

Maybe you defined one provider like <provider>org.hibernate.ejb.HibernatePersistence</provider> but referencing another one in jar. That happened with me: my persistence.xml provider was openjpa but I was using eclipselink in my classpath. Hope this help!

Gilbertoca
A: 

Corner case: if you are using m2Eclipse, it automatically puts in excludes on your resources folders. Then when you try to run tests inside eclipse, the subsequent absence of persistence.xml will produce this error.

Rob
A: 

it happenes when the entity manager is trying to point to many persistence units...do the following steps.. 1.open the related file in word pad(provided your project has been closed in your ide) 2.delete all the persistence and entity manager related code. 3.save the file 4.open the project in your ide. 5.now bind the db or table of your choice.

it works fine for me.. hope it was helpfull...

mahesh