Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EclipseLink : No Persistence provider for EntityManager named

I'd like to create one Bundle that is able to use Java Persistence. To achieve this, I've created a plugin project within Eclipse. In my project, I've created a persistence.xml file into META-INF. I've aslo added in my MANIFEST.mf (into the depencies) those 3 packages :

  1. javax.persistence.jar
  2. org.eclipse.persistence.jar
  3. org.eclipse.persistence.jar

Then, in my Activator I use this lines to create an EntityManager :

factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); 
EntityManager em = factory.createEntityManager();

To execute my bundle, I've made a product configuration. When I run my product configuration, I got this error :

javax.persistence.PersistenceException: No Persistence provider for EntityManager named people

I've tried to move the location of my persistence.xml without success. It seems that any package load the persistence.xml file. Maybe, I don't import the right packages?

You can download my simple Bundle here : download

Could you help me to find a solution or a clue?

like image 497
user376112 Avatar asked Jul 12 '10 17:07

user376112


3 Answers

I've solved my problem. I only had to put in the classpath of the manifest this packages : - persistence.jar - eclipselink.jar - mysql-connector.jar

Thanks

like image 157
user376112 Avatar answered Nov 06 '22 16:11

user376112


Try adding this tag in the persistence.xml:

<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
like image 4
Bozho Avatar answered Nov 06 '22 17:11

Bozho


I was getting the same error in a simple project running in Eclipse.

It turns out that adding the META-INF directory (containing persistence.xml) to my class path was the wrong thing to do.

You have to have its containing dir (or jar) on the class path. From the EclipseLink 2.5.1 sources:

   /**
     * Search the classpath for persistence archives. A persistence archive is
     * defined as any part of the class path that contains a META-INF directory
     * with a persistence.xml file in it. Return a list of {@link Archive}
     * representing the root of those files. It is the caller's responsibility
     * to close all the archives.
     * 
     * @param loader the class loader to get the class path from
     */
    public static Set<Archive> findPersistenceArchives(ClassLoader loader){
        // allow alternate persistence location to be specified via system property.  This will allow persistence units
        // with alternate persistence xml locations to be weaved
        String descriptorLocation = System.getProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML_DEFAULT);
        return findPersistenceArchives(loader, descriptorLocation);
    }
like image 3
JasonPlutext Avatar answered Nov 06 '22 16:11

JasonPlutext