EclipseLink:没有名为EntityManager的持久性提供程序

时间:2010-07-12 17:48:24

标签: java jpa osgi eclipselink equinox

我想创建一个能够使用Java Persistence的Bundle。为此,我在Eclipse中创建了一个插件项目。在我的项目中,我已经在META-INF中创建了一个persistence.xml文件。我已经在我的MANIFEST.mf(加入依赖项)中添加了这3个包:

  1. javax.persistence.jar
  2. org.eclipse.persistence.jar
  3. org.eclipse.persistence.jar
  4. 然后,在我的Activator中,我使用这些行创建一个EntityManager:

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

    要执行我的捆绑包,我已经进行了产品配置。当我运行我的产品配置时,我收到了这个错误:

      

    javax.persistence.PersistenceException:没有名为people的EntityManager的持久性提供程序

    我试图移动persistence.xml的位置但没有成功。似乎任何包加载persistence.xml文件。也许,我没有导入正确的包裹?

    您可以在此处下载我的简单套装:download

    你能帮我找一个解决方案或线索吗?

5 个答案:

答案 0 :(得分:6)

我已经解决了我的问题。我只需要在清单中放入这个包的类路径: - persistence.jar - eclipselink.jar - mysql-connector.jar

由于

答案 1 :(得分:4)

尝试在persistence.xml

中添加此标记
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

答案 2 :(得分:2)

您似乎没有使用JPA-PersistenceUnits:header在MANIFEST.MF中描述您的持久性单元。您可以在此处找到有关EclipseLink的更多详细信息(1)。

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

答案 3 :(得分:2)

我在Eclipse中运行的一个简单项目中遇到了同样的错误。

事实证明,将META-INF目录(包含persistence.xml)添加到我的类路径是错误的。

你必须在类路径上包含它的dir(或jar)。来自EclipseLink 2.5.1来源:

   /**
     * 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 :(得分:1)

如果您使用Maven在eclipse中运行应用程序,请右键单击JPA项目,选择“属性”,然后查看是否存在“部署程序集”菜单项。如果是这样,请单击Deployment assembly,单击Add ...按钮,单击Java Build Path Entries,然后选择Maven Dependencies。确保eclipselink.jar属于Maven依赖项