Java SE 上的 openJPA

发布于 2024-08-18 14:13:22 字数 2726 浏览 6 评论 0原文

我尝试在 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)

我缺少什么?

根据我的 persisted.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>**

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:

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:

**<?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>**

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

话少心凉 2024-08-25 14:13:22

只是一个指针:
您需要增强您的类,例如在运行时通过 -javaagent:yourlib.jar
甚至在编译时。您可以在此处了解有关此主题的更多信息:

“第二个获得运行时增强的推荐方法是在启动 OpenJPA 将要运行的 JVM 时提供 javaagent。”

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:

"The second and recommended way get runtime enhancement is to provide a javaagent when launching the JVM that OpenJPA is going run in."

愛放△進行李 2024-08-25 14:13:22

我刚刚完成了让 OpenJPA 2.1.0 在 Tomcat 7.0 上运行的练习。我根本无法让运行时增强在 Tomcat 下工作,所以我放弃并决定使用构建时增强。我正在 Eclipse 下开发代码,因此我按照此处的说明进行操作:

http://openjpa.apache .org/enhancement-with-eclipse.html

但请注意,此页面上的说明适用于通用 Java 项目。如果您正在使用动态 Web 项目,请确保正确指定构建目录参数。我使用 -Dbuild.dir=build/classes 这是编译代码的典型位置。

您必须忍受的又一个恼人的怪癖。您必须使用“Project > Build Project”菜单项手动调用构建器。当增强器运行时,它会修改先前构建的类。因此,在发布到 Tomcat 之前,您需要对项目按 F5 或刷新。

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:

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文