Google App Engine JPA 2.0 - java.lang.ClassNotFoundException:javax.persistence.spi.ProviderUtil

时间:2013-02-05 21:57:36

标签: java google-app-engine jpa-2.0 maven-3 datanucleus

I have been scouring the internet for hours today并且无法解决此问题。

我正在尝试将我的Google App Engine项目配置为使用JPA 2.0以及最新版本的Datanucleus软件包。一切都编译得很好,但我一直得到运行时异常:

Caused by: java.lang.ClassNotFoundException: javax.persistence.spi.ProviderUtil

我包含了pom.xml的相关部分,其中涉及所有持久性内容以及我的persistence.xml文件。

以下是我认为pom.xml的相关部分:

<gae.version>1.7.4</gae.version>
<datanucleus.version>3.1.1</datanucleus.version>

<dependency>
    <groupId>javax.jdo</groupId>
    <artifactId>jdo-api</artifactId>
    <version>3.0.1</version>
</dependency>
<dependency>
    <groupId>org.apache.geronimo.specs</groupId>
    <artifactId>geronimo-jpa_2.0_spec</artifactId>
    <version>1.1</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>${datanucleus.version}</version>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-api-jpa</artifactId>
    <version>${datanucleus.version}</version>
</dependency>
<dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-api-jdo</artifactId>
    <version>${datanucleus.version}</version>
</dependency>

<plugin>
    <groupId>org.datanucleus</groupId>
    <artifactId>maven-datanucleus-plugin</artifactId>
    <version>${datanucleus.version}</version>
    <configuration>
        <api>JPA</api>
        <verbose>true</verbose>
    </configuration>
    <executions>
        <execution>
            <phase>process-classes</phase>
            <goals>
                <goal>enhance</goal>
            </goals>
        </execution>
    </executions>
 </plugin>

以下是我的persistence.xml文件内容: I updated the provider as per the instructions on the Google App Engine web site

<?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.PersistenceProviderImpl</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: java.lang.ClassNotFoundException: javax.persistence.spi.ProviderUtil
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:213)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 56 more

有人可以指出我正确的方向,我缺少什么依赖?

最新图书馆需要的Datanucleus,Google和JPA依赖项的确切版本是什么?

2 个答案:

答案 0 :(得分:2)

您说您正在使用JPA 2.0,但是您在CLASSPATH中放置了 geronimo-jpa_3.0_spec v1.1.1 ,那就是JPA 1.0 API。根据{{​​3}} POM,使用 geronimo-jpa_2.0_spec v1.1 会更有意义,因为它是JPA 2.0 API。 GAE JPA插件和DataNucleus兼容性在GAE JPA plugin

中定义

答案 1 :(得分:0)

使用Google AppEngine DataNucleus plugin

<dependency>
    <groupId>com.google.appengine.orm</groupId>
    <artifactId>datanucleus-appengine</artifactId>
    <version>2.1.2</version>
</dependency>