openjpa一個問題

今天遇到問題:html

在作openjpa開發時,運行jsp文件出現以下錯誤:<openjpa-2.4.1-r422266:1730418 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: "java

程序在java測試時openjpa沒問題,用jsp調用出現如上錯誤apache

查網上找到一解決辦法,連接爲:http://rockyfeng.me/jpa_entity.htmldom

出現下列錯誤

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
相關文章
相關標籤/搜索