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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3230798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 17:37:10  来源:igfitidea点击:

EclipseLink : No Persistence provider for EntityManager named

javajpaosgieclipselinkequinox

提问by user376112

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 :

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

然后,在我的 Activator 中,我使用这一行来创建一个 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

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

I've tried to move the location of my persistence.xmlwithout success. It seems that any package load the persistence.xmlfile. Maybe, I don't import the right packages?

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

You can download my simple Bundle here : download

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

Could you help me to find a solution or a clue?

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

回答by Bozho

Try adding this tag in the persistence.xml:

尝试在 中添加此标签persistence.xml

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

回答by 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).

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

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

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

回答by user376112

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

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

Thanks

谢谢

回答by Ayco Holleman

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

如果您使用 Maven 从 Eclipse 中运行您的应用程序,请右键单击 JPA 项目,选择“属性”,然后查看是否有“部署程序集”菜单项。如果是这样,请单击部署程序集,单击添加...按钮,单击 Java 构建路径条目,然后选择 Maven 依赖项。确保 eclipselink.jar 在 Maven 依赖项中

回答by JasonPlutext

I was getting the same error in a simple project running in Eclipse.

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

It turns out that adding the META-INF directory (containing persistence.xml) to my class path was the wrong thing to do.

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

You have to have its containing dir (or jar) on the class path. From the EclipseLink 2.5.1 sources:

您必须在类路径上拥有它的包含目录(或 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);
    }