0

我一直在学习一些关于谷歌应用引擎教程的 jpa。在所有教程中,都没有在 persistence.xml 中指定实体类。但是我的本地环境抛出了 NoPersistenceInformationException。“de.vogella.gae.java.todo.model.Todo”类必须是可持久的,但找不到此类的元数据/注释。请检查元数据/注释是否定义在有效的文件位置。

如果我在 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">

<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

4

1 回答 1

1

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

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

persistence.xml 中的类元素

于 2013-01-24T01:29:16.557 回答