EclipseLink : No Persistence provider for EntityManager named

房东的猫 提交于 2019-12-05 07:30:53

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

Try adding this tag in the persistence.xml:

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

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

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

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

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