JPA cannot find persistence provider

I'm using IntelliJ IDEA 9 M1 in Mac OS for a project with JPA persistence.
It's compiled without any problem but running the program cause the following error.

javax.persistence.PersistenceException: No Persistence provider for EntityManager named agisdb-PU
     at javax.persistence.Persistence.createEntityManagerFactory(
     at javax.persistence.Persistence.createEntityManagerFactory(
     at com.agis.livedb.domain.util.PersistenceUtil.getAgisDbEntityManager(

Here is the persistence.xml I have

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="" version="1.0">
    <persistence-unit name="agisdb-PU">
            <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"/>

And below is how I get the entity manager factory...

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

I have already checked the classpath shown when I run the application, and it has already included the compilation output directory. And I have verified that the persistence.xml is inside the META-INF directory under that directory.

Is there any additional setting I need to add?
Thank you,

Comment actions Permalink

That's an JPA question rather than an IDEA question, but anyway:
My persistence.xml explicitly specifies the provider in a tag directly nested inside the <persistence-unit> tag:

If you are not using Hibernate, but have correctly added the jar file containing the provider in IDEA, then you can probably quickly find out the correct classname for your provider by
ctrl-n, PersistenceProvider (that should take you to the interface)
then ctrl-alt-b which should go to the implementation class of your provider.

Comment actions Permalink

Hi, thanks Stephen! I got to find the persistenceprovider and put it in the library.


Please sign in to leave a comment.