开发者

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 E开发者_如何学JAVAntityManager 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?


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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜