GAE上JPA的persistence.xml中的实体类

时间:2013-01-24 01:04:53

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

我一直在使用Google app引擎教程中的一些jpa。在所有教程中,未在persistence.xml中指定实体类。但是我的本地环境会抛出NoPersistenceInformationException。 “de.vogella.gae.java.todo.model.Todo”类必须是可持久的,但是没有为此类找到Meta-Data / Annotations。请检查元数据/注释是否在有效的文件位置中定义。

如果我在persistence.xml中指定实体类,则问题就会消失。

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" 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">
<persistence-unit name="transactions-optional">
<provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
<class>de.vogella.gae.java.todo.model.Todo/class>
<properties>
  <property name="datanucleus.NontransactionalRead" value="true"/>
  <property name="datanucleus.NontransactionalWrite" value="true"/>
  <property name="datanucleus.ConnectionURL" value="appengine"/>
  <property name="datanucleus.singletonEMFForName" value="true"/>
  <property name="datanucleus.appengine.datastoreEnableXGTransactions" value="true"/>
</properties>

有人可以向我解释为什么我需要在我的情况下这样做吗? GAE教程中的JPA都不需要这样做。一个区别是我使用google appengine maven插件而不是eclipse插件。

这是我的pom文件

   http://maven.apache.org/xsd/maven-4.0.0.xsd“&GT;

<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>

<groupId>de.vogella.gae.java.todo</groupId>
<artifactId>todo</artifactId>

<pluginRepositories>
    <pluginRepository>
        <id>google-snapshots</id>
        <name>Google Snapshots</name>
        <url>https://oss.sonatype.org/content/repositories/google-snapshots/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <releases>
            <enabled>false</enabled>
        </releases>
    </pluginRepository>
</pluginRepositories>

<properties>
    <appengine.app.version>1</appengine.app.version>
    <appengine.target.version>1.7.4</appengine.target.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <!-- Compile/runtime dependencies -->
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-api-1.0-sdk</artifactId>
        <version>${appengine.target.version}</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

    <!-- JPA dependencies -->
    <dependency>
        <groupId>com.google.appengine.orm</groupId>
        <artifactId>datanucleus-appengine</artifactId>
        <version>2.0.1.1</version>
    </dependency>
    <dependency>
        <groupId>javax.jdo</groupId>
        <artifactId>jdo-api</artifactId>
        <version>[3.0, 4.0)</version>
    </dependency>
    <dependency>
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-jpa_2.0_spec</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-core</artifactId>
        <version>[3.0, 3.0.99)</version>
    </dependency>
    <dependency>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-api-jpa</artifactId>
        <version>[3.0, 3.0.99)</version>
    </dependency>
    <dependency>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-jpa-query</artifactId>
        <version>3.0.2</version>
    </dependency>

    <!-- Test Dependencies -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.9.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-testing</artifactId>
        <version>${appengine.target.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-api-stubs</artifactId>
        <version>${appengine.target.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxrs</artifactId>
        <version>2.3.5.Final</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jackson-provider</artifactId>
        <version>2.3.5.Final</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <version>2.5.1</version>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <!-- compilerArguments>
                    <processor>org.datanucleus.jpa.query.JPACriteriaProcessor</processor>
                </compilerArguments -->                 
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <archiveClasses>true</archiveClasses>
                <webResources>
                    <!-- in order to interpolate version from pom into appengine-web.xml -->
                    <resource>
                        <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                        <filtering>true</filtering>
                        <targetPath>WEB-INF</targetPath>
                    </resource>
                </webResources>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-maven-plugin</artifactId>
            <version>1.7.5-SNAPSHOT</version>
            <configuration>
                <jvmFlags>
                    <jvmFlag>-Xdebug</jvmFlag>
                    <jvmFlag>-Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=n</jvmFlag>
                    <jvmFlag>-Ddatastore.default_high_rep_job_policy_unapplied_job_pct=20</jvmFlag>
                </jvmFlags>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.datanucleus</groupId>
            <artifactId>maven-datanucleus-plugin</artifactId>
            <version>3.0.2</version>
            <configuration>
                <api>JPA</api>
                <persistenceUnitName>transactions-optional</persistenceUnitName>
                <!-- log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration -->
                <verbose>true</verbose>
            </configuration>
            <executions>
                <execution>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>enhance</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

这是我正在进行的教程http://www.vogella.com/articles/GoogleAppEngineJava/article.html

1 个答案:

答案 0 :(得分:1)

我猜我的谷歌搜索技巧很弱,因为我在询问之前没有找到答案......

但是这个问题已经在stackoverflow上被问到了......

class elements in persistence.xml