您可能应该使用编译时增强而不是 javaagent 的运行时增强。
如果您正在使用 m2eclipse(您可能会这样做),则使用以下内容就足够了:
<persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<properties>
<property name="openjpa.jdbc.DBDictionary" value="org.apache.openjpa.jdbc.sql.H2Dictionary"/>
<!-- value="buildSchema" to runtime forward map the DDL SQL; value="validate" makes no changes to the database -->
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
<property name="openjpa.RuntimeUnenhancedClasses" value="unsupported"/>
</properties>
</persistence-unit>
在你的 pom.xml 的 build 部分你应该有类似的东西:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>openjpa-maven-plugin</artifactId>
<version>1.2</version>
<configuration>
<includes>**/*.class</includes>
<excludes>**/*_Roo_*.class</excludes>
<addDefaultConstructor>true</addDefaultConstructor>
</configuration>
<executions>
<execution>
<id>enhancer</id>
<phase>compile</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
<execution>
<id>test-enhancer</id>
<phase>test-compile</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<version>${openjpa.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_1.1_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</plugin>
请注意,roo 可能会生成可能无法正常工作的不同 xml 片段(IIRC 它使用不同的输出目录)。
在你清理你的项目类之后应该得到增强。