Java SE 上的 openJPA
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2127263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
openJPA on Java SE
提问by qasanov
I try to develop JPA project on ibm RAD. And i can run it on Webpshere successfully, but the problem is my machine is quite old. So deploying in Java EE container isn't reasonable.And i want to run it on JSE.But it gives following error:
我尝试在 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)
What i'm missing?
我缺少什么?
By the my persistent.xml is:
我的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>**
回答by Karussell
Just a pointer: You need to enhance your classes e.g. at runtime via -javaagent:yourlib.jar or even while compiling. You could learn more on this topic here:
只是一个指针:您需要增强您的类,例如在运行时通过 -javaagent:yourlib.jar 或什至在编译时。您可以在此处了解有关此主题的更多信息:
"The second and recommended way get runtime enhancement is to provide a javaagent when launching the JVM that OpenJPA is going run in."
“获得运行时增强的第二种也是推荐的方法是在启动 OpenJPA 将要运行的 JVM 时提供一个 javaagent。”
回答by Rangachari Anand
I just went through the exercise of getting OpenJPA 2.1.0 to run on Tomcat 7.0. I was simply unable to get run-time enhancement to work under Tomcat so I gave up and decided to use build-time enhancement. I am developing my code under Eclipse so I followed the instructions here:
我刚刚完成了让 OpenJPA 2.1.0 在 Tomcat 7.0 上运行的练习。我只是无法在 Tomcat 下获得运行时增强功能,所以我放弃并决定使用构建时增强功能。我正在 Eclipse 下开发我的代码,所以我按照这里的说明进行操作:
http://openjpa.apache.org/enhancement-with-eclipse.html
http://openjpa.apache.org/enhancement-with-eclipse.html
Note however that the instructions on this page are for generic java projects. If you are working with Dynamic Web Projects, be sure to specify the build directory argument correctly. I used -Dbuild.dir=build/classes which is the typical location for the compiled code.
但是请注意,此页面上的说明适用于通用 java 项目。如果您正在使用动态 Web 项目,请确保正确指定构建目录参数。我使用 -Dbuild.dir=build/classes 这是编译代码的典型位置。
One more annoying quirk you have to live with. You must manually invoke the builder using the "Project > Build Project" menu item. When the enhancer runs, it modifies the previously built classes. Consequently, you need to hit F5 or Refresh for the project before you publish to Tomcat.
您必须忍受的另一个令人讨厌的怪癖。您必须使用“项目 > 构建项目”菜单项手动调用构建器。当增强器运行时,它会修改之前构建的类。因此,在发布到 Tomcat 之前,您需要为项目点击 F5 或刷新。

