我尝试在ibm RAD上开发JPA项目。我可以成功地在Webpshere上运行它, 但问题是我的机器很老了。因此,在Java EE容器中部署不是 合理。我想在JSE上运行它。但是它给出了以下错误:
94 test INFO [main] openjpa.Runtime - Starting OpenJPA 1.2.1-SNAPSHOT
235 test INFO [main] openjpa.jdbc.JDBC - Using dictionary class "com.ibm.ws.persistence.jdbc.sql.DB2Dictionary".
1797 test WARN [main] openjpa.Enhance - This configuration disallows runtime optimization, but the following listed types were not enhanced at build time or at class load time with a javaagent: "[class Customer]".
Exception in thread "main" <openjpa-1.2.1-SNAPSHOT-r422266:686069 fatal user error> org.apache.openjpa.persistence.ArgumentException: The type "class Customer" has not been enhanced.
at org.apache.openjpa.meta.ClassMetaData.resolveMeta(ClassMetaData.java:1650)
at org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1624)
at org.apache.openjpa.meta.MetaDataRepository.processBuffer(MetaDataRepository.java:717)
at org.apache.openjpa.meta.MetaDataRepository.resolveMeta(MetaDataRepository.java:616)
at org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:541)
at org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:308)
at org.apache.openjpa.kernel.BrokerImpl.newObjectId(BrokerImpl.java:1114)
at org.apache.openjpa.kernel.DelegatingBroker.newObjectId(DelegatingBroker.java:268)
at org.apache.openjpa.persistence.EntityManagerImpl.find(EntityManagerImpl.java:451)
at deneme.main(deneme.java:21)
我缺少什么?
我的persistent.xml是:
**<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
<provider>
com.ibm.websphere.persistence.PersistenceProviderImpl
</provider>
<class>Customer</class>
<properties>
<property name="openjpa.ConnectionDriverName" value="com.ibm.db2.jcc.DB2Driver"/>
<property name="openjpa.ConnectionURL" value="jdbc:db2://localhost:50000/PARUD:retrieveMessagesFromServerOnGetMessage=true;"/>
<property name="openjpa.ConnectionUserName" value="db2admin"/>
<property name="openjpa.ConnectionPassword" value="xxxxx"/>
<property name="openjpa.jdbc.Schema" value="POOL"/>
</properties>
</persistence-unit>
</persistence>**
答案 0 :(得分:8)
只是一个指针: 你需要增强你的课程,例如在运行时通过-javaagent:yourlib.jar 甚至在编译时。您可以了解有关此主题的更多信息here:
“第二种推荐的运行时增强方法是在启动OpenJPA运行的JVM时提供javaagent。”
答案 1 :(得分:0)
我刚刚完成了使用OpenJPA 2.1.0在Tomcat 7.0上运行的练习。我根本无法获得在Tomcat下运行的运行时增强功能,因此我放弃了并决定使用构建时增强功能。我正在Eclipse下开发代码,所以我按照这里的说明进行操作:
http://openjpa.apache.org/enhancement-with-eclipse.html
但请注意,此页面上的说明适用于通用Java项目。如果您正在使用Dynamic Web Projects,请确保正确指定构建目录参数。我使用了-Dbuild.dir = build / classes,这是编译代码的典型位置。
你必须忍受一个令人烦恼的怪癖。您必须使用“Project&gt; Build Project”菜单项手动调用构建器。当增强器运行时,它会修改以前构建的类。因此,在发布到Tomcat之前,需要为项目点击F5或Refresh。