openjpa一个问题

今天遇到问题:

在做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测试时openjpa没问题,用jsp调用出现如上错误

查网上找到一解决办法,链接为:http://rockyfeng.me/jpa_entity.html



出现下列错误

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

   

 

转载于:https://my.oschina.net/u/574158/blog/746003

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值