7

我想创建一个能够使用 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

然后,在我的 Activator 中,我使用这些行来创建一个 EntityManager :

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

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

javax.persistence.PersistenceException:EntityManager 命名人员没有持久性提供程序

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

你可以在这里下载我的简单包:下载

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

4

5 回答 5

6

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

谢谢

于 2010-07-14T07:12:06.587 回答
4

尝试将此标签添加到persistence.xml

<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
于 2010-07-12T17:50:03.680 回答
3

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

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

您必须在类路径上有其包含的目录(或 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);
    }
于 2014-06-01T02:57:59.580 回答
2

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

于 2012-09-14T11:28:17.693 回答
2

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

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

于 2010-07-13T08:13:18.440 回答