【问题标题】:No Persistence provider for EntityManager?EntityManager 没有持久性提供程序?
【发布时间】:2013-06-20 20:57:54
【问题描述】:

我正在尝试建立一个基本的 JPA。但我什至无法获得EntityManger。以下配置可能有什么问题?

private static final EntityManager emf = Persistence
.createEntityManagerFactory("transactions-optional").createEntityManager();

src/META-INF/persistence.xml(也试过:src/main/webapp/WEB-INF/classes/META-INF/):

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
        http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">

    <persistence-unit name="transactions-optional">
        <provider>org.datanucleus.api.jpa.PersistenceProviderImp</provider>
        <properties>
            <property name="datanucleus.NontransactionalRead" value="true"/>
            <property name="datanucleus.NontransactionalWrite" value="true"/>
            <property name="datanucleus.ConnectionURL" value="appengine"/>
        </properties>
    </persistence-unit>
</persistence>

结果:

Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named transactions-optional
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
    at de.verism.server.database.EMFService.<clinit>(EMFService.java:13)

Maven 配置:

   <dependency>
        <groupId>javax.jdo</groupId>
        <artifactId>jdo2-api</artifactId>
        <version>2.3-eb</version>
        <exclusions>
            <!--
                exclude the legacy javax.transaction:transaction-api
                and replace it with javax.transaction:jta (it
                appears to be the same thing)
            -->
            <exclusion>
                <groupId>javax.transaction</groupId>
                <artifactId>transaction-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <groupId>com.google.appengine.orm</groupId>
        <artifactId>datanucleus-appengine</artifactId>
        <version>2.1.2</version>
    </dependency>
    <dependency>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-core</artifactId>
        <version>3.2.4</version>
        <exclusions>
            <exclusion>
                <groupId>javax.transaction</groupId>
                <artifactId>transaction-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>datanucleus-jpa</artifactId>
        <version>1.1.5</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>geronimo-jpa_3.0_spec</artifactId>
        <version>1.1.1</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-api-1.0-sdk</artifactId>
        <version>${gae.version}</version>
    </dependency>

更新配置:

        <dependency>
            <groupId>com.google.appengine.orm</groupId>
            <artifactId>datanucleus-appengine</artifactId>
            <version>2.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-core</artifactId>
            <version>3.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-api-jpa</artifactId>
            <version>3.1.1</version>
        </dependency>
<dependency>
    <groupId>org.apache.geronimo.specs</groupId>
    <artifactId>geronimo-jpa_2.0_spec</artifactId>
    <version>1.1</version>
    <scope>runtime</scope>
</dependency>

【问题讨论】:

  • org.datanucleus.api.jpa.PersistenceProviderImp 在您的类路径中正确添加了吗?
  • 是的,它是由上面更新的 maven 配置添加的。

标签: java google-app-engine gwt jpa


【解决方案1】:

我认为问题在于提供程序类中缺少 l

org.datanucleus.api.jpa.PersistenceProviderImpl

【讨论】:

    【解决方案2】:

    Google 的 datanucleus-appengine 2.1.x 需要 DataNucleus 3.1.x(不是 3.2.x)。 你应该有 jdo-api v3.x(不是 jdo2-api v2.3.x)。 如果使用 JPA,您需要“datanucleus-api-jpa”v3.1.x(不是“datanucleus-jpa”v1.x)。 然后您还需要“geronimo-jpa-2.0_spec”v1.x(不是 geronimo-jpa-3.0_spec v1.x)。

    是的,我认为可以公平地说您完全是 messed up the dependencies ;-) 然后当你修复了你使用GAE docs 来设置持久性提供者

    【讨论】:

    • 谁更了解它?
    • 谢谢,但使用上面更新的 maven 配置仍然存在错误
    • 所以看看那些 GAE 文档,它们会告诉你所有要做的事情。当然,日志也是如此。
    • 好吧,如果日志告诉我“EntityManager 没有名为 transactions-optional 的持久性提供程序”并且我的 persistence.xml 定义了“transactions-optional”持久性单元,我很遗憾不知道我能做什么做其他...
    • 然后它无法找到您的 persistence.xml(并且“src”下的位置在运行时不相关,所以也许说明它在运行时的位置)。
    【解决方案3】:

    我有同样的问题。查看META-INF,有两个文件名为:

    • jdoconfig.xml
    • persistence.xml

    如果你使用的是持久化api,那么你可以通过在jdoconfig.xml文件中添加块注释来摆脱这个错误

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-04
      • 2012-06-21
      • 1970-01-01
      • 1970-01-01
      • 2017-01-17
      • 2011-05-14
      • 2014-12-15
      相关资源
      最近更新 更多