EclipseLink : No Persistence provider for EntityManager named

不问归期 提交于 2020-01-02 03:53:09

问题


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?


回答1:


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




回答2:


Try adding this tag in the persistence.xml:

<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>



回答3:


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);
    }



回答4:


It seems that you did not describe your persistence unit in MANIFEST.MF with JPA-PersistenceUnits: header. You can find more details for EclipseLink here (1).

(1): http://wiki.eclipse.org/Gemini/JPA/Documentation/CreatingAnApplication




回答5:


If you are running your app from within eclipse using Maven, right-click on the JPA project, choose Properties, and see if there is a "Deployment Assembly" menu item. If so, click on Deployment assembly, Click the Add... button, Click Java Build Path Entries, and then select Maven Dependencies. Make sure eclipselink.jar is amongst the Maven dependencies



来源:https://stackoverflow.com/questions/3230798/eclipselink-no-persistence-provider-for-entitymanager-named

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!