Date Tags Java / JPA

出现下列错误

Caused by: <openjpa-2.2.0-r422266:1244990 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: This configuration disallows runtime optimization, but the following listed types were not enhanced at build time or at class load time with a javaagent: "
com.example.jpastudy.Message".

解决方法1, 在persistence.xml中添加

<property name="openjpa.RuntimeUnenhancedClasses" value="supported" />

但不提倡这么做,这样会导致openjpa在运行时对entity类进行增强而导致性能下降。 我们应该用编译时的增强。

解决方法2, 在pom.xml中加入以下代码

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.openjpa</groupId>
            <artifactId>openjpa-maven-plugin</artifactId>
            <version>2.2.0</version>
            <configuration>
                <includes>**/domain/*.class</includes>
                <excludes>**/domain/XML*.class</excludes>
                <addDefaultConstructor>true</addDefaultConstructor>
                <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
            </configuration>
            <executions>
                <execution>
                    <id>enhancer</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>enhance</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.apache.openjpa</groupId>
                    <artifactId>openjpa</artifactId>
                        <!-- set the version to be the same as the level in your runtime -->
                    <version>2.2.0</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

并在persitence.xml中加入

<property name="openjpa.RuntimeUnenhancedClasses" value="unsupported" />
<property name="openjpa.DynamicEnhancementAgent" value="false" />

运行mvn 之前都运行一下

mvn openjpa:enhance