我的问题是这个异常:
Caused by: <openjpa-2.1.1-r422266:1148538 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: "
我试图获得一个运行 jsf 和 jpa 的非常简单的 java 应用程序,但我的实体的增强似乎存在问题。据我所知,尝试 OpenJPA 在运行时增强我的实体,这些实体列在persistence.xml
,但是没有代理可以执行此操作。这个的关键字是:Enhancing at Runtime
, right?
我认为增强功能会在部署时由应用程序服务器自动完成?我该如何配置这个?
我的确切环境:
- 玻璃鱼3.1.1
- Derby,集成在 Glassfish 中
- OpenJPA 2.1.1
- 莫贾拉 JSF 2.1.3
更新#1:
经过一些评论后,我将以下行添加到我的persistence.xml
:
<property name="openjpa.DynamicEnhancementAgent" value="false"/>
<property name="openjpa.RuntimeUnenhancedClasses" value="supported" />
现在可以工作了,但 OpenJPA 会抛出此警告:
SEVERE: 52 myApp WARN [http-thread-pool-8080(5)] openjpa.Enhance - Creating subclass for "[class myApp.model.entities.AbstractEntity, class myApp.model.entities.Post]".
This means that your application will be less efficient and will consume more memory than it would if you ran the OpenJPA enhancer. Additionally, lazy loading will not be available for one-to-one and many-to-one persistent attributes in types using field access; they will be loaded eagerly instead.
我认为这不能成为解决方案。
更新#2:
参考fvu的答案,我试图定义-javaagent
jvm参数中domain.xml
并通过网络管理控制台。重启后又出现这个问题。
更新#3:
请参阅更新#2,我已经玩了一下。当-javaagent
使用了参数,但是文件丢失了,对吗?是的,就是这样:
Waiting for domain1 to start .Command start-domain failed.
Error starting domain domain1.
The server exited prematurely with exit code 1.
Before it died, it produced the following output:
Error occurred during initialization of VM
agent library failed to init: instrument
Error opening zip file or JAR manifest missing : /tmp/openjpa.jar
如果我将代理复制到此位置,则不会出现此错误,但 openjpa 仍然无法增强我的实体!