Glassfish 3.1.1上的OpenJPA 2.1.1增强问题

时间:2011-09-03 18:06:42

标签: jsf java-ee jpa glassfish openjpa

我的问题是这个例外:

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,对吧?

我认为增强会在部署时由应用服务器自动完成吗?我该如何配置?

我的确切环境:

  • Glassfish 3.1.1
  • Derby,集成在Glassfish
  • OpenJPA 2.1.1
  • Mojarra 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和Web管理控制台中定义domain.xml jvm参数。重新启动后再次出现问题。

更新#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仍无法增强我的实体!

2 个答案:

答案 0 :(得分:3)

如果您仍有问题......我强烈建议您咬紧牙关并设置build time增强功能。如果你顺利的话,从长远来看你会更开心。

答案 1 :(得分:1)

一些想法:

  • 添加Java代理以增强GF的JVM选项,请参阅this link以获取如何安装javaagent和OpenJPA的doc 5.2.3的示例,并在运行时进行增强。这样可以尽可能地模拟桌面应用程序中的增强器激活IMO。

但是,当我阅读OpenJPA文档的第5.2.4章时,它可能能够自动获取正确的增强器。尝试将openjpa.jar复制到域的库目录,并检查服务器重启后会发生什么。