GAE的JPA注释/元数据映射

时间:2016-01-21 02:44:56

标签: java google-app-engine jpa datanucleus

我正在尝试完成我计划在Google应用引擎上部署的应用的建模。

我有一个基类,Account是抽象的,注释如下:

@Entity
@MappedSuperclass
public abstract class Account {

    @Id
    private Key id;
    .....

然后我有两个具体的类,AdministratorAccount:

@Entity
public class AdministratorAccount extends Account {

和CustomerAccount:

@Entity
public class CustomerAccount extends Account {

我还在persistence.xml文件中声明了所有3个。

当我尝试持有CustomerAccount时,我收到500错误:

org.datanucleus.exceptions.NoPersistenceInformationException: The class "com.nucleus.entitymodel.Account" is required to be persistable yet no Meta-Data/Annotations can be found for this class. Please check that the Meta-Data/annotations is defined in a valid file location.

关于问题可能是什么的任何想法?我试图按照GAE网站上的文档进行JPA继承。

1 个答案:

答案 0 :(得分:0)

请注意Google warning关于JPA的问题,请考虑迁移到Objectify或他们的低级数据存储区。

您的警告表明您的JPA实体类未得到增强。 Google的数据存储区运行在datanucleus上,并且要求为持久性增强类。 这可以使用maven插件来完成,例如;

        <plugins>
        <!-- This plug-in "enhances" your domain model objects (i.e. makes them persistent for datanucleus) -->
        <plugin>
            <groupId>org.datanucleus</groupId>
            <artifactId>maven-datanucleus-plugin</artifactId>
            <version>${datanucleus.version}</version>
            <configuration>
                <fork>false</fork>
                <!-- Make sure this path contains your persistent classes! -->
                <mappingIncludes>**/model/*.class</mappingIncludes>
                <verbose>true</verbose>
                <enhancerName>ASM</enhancerName>
                <api>JPA</api>
            </configuration>
            <executions>
                <execution>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>enhance</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <!-- force maven-datanucleus-plugin to use the same version of datanucleus-core -->
                <dependency>
                    <groupId>org.datanucleus</groupId>
                    <artifactId>datanucleus-core</artifactId>
                    <version>${datanucleus.version}</version>
                </dependency>
            </dependencies>
        </plugin>