【问题标题】:JPA 2.0 issue on Websphere 7.0 using RSA 8.5使用 RSA 8.5 的 Websphere 7.0 上的 JPA 2.0 问题
【发布时间】:2013-12-24 02:42:20
【问题描述】:

我在让我的应用程序在 WAS 7.0 上使用 JPA 2.0 运行时遇到问题。我正在使用 RSA 8.5 进行开发。我使用 Hibernate 作为提供程序。
这是我到目前为止所做的:

  1. 我使用 JPA 2.0 facet 配置了我的项目。

  2. 将所有休眠“必需”jar 和 jpa jar 添加到构建中 路径以及清单条目中。

  3. 我关注了这篇文章:Alternate JPA Providers in WebSphere Application Server 我通过管理控制台更改了默认的持久性提供程序,并且在服务器启动时在日志中看到了这些行:

    [12/6/13 9:36:20:529 EST] 00000000 JPAComponentI I   CWWJP0026I: The Java Persistence API (JPA) component is initializing.
    [12/6/13 9:36:20:537 EST] 00000000 JPAComponentI I   CWWJP0006I: The org.hibernate.ejb.HibernatePersistence class is loaded as the default Java Persistence API (JPA) provider.
    
  4. 这是我的应用程序的 persistence.xml:

    <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.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_2_0.xsd">
    <persistence-unit name="biReconWeb">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <property name="hibernate.transaction.factory_class"
    value="org.hibernate.transaction.JTATransactionFactory"/>         <property
    name="hibernate.transaction.manager_lookup_class"
    value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup"/>
    

  5. 在服务器中,我使用以下 jar 创建了一个共享库,并创建了一个引用此共享库的“应用程序优先”类加载器:

antlr-2.7.7.jar

hibernate-commons-annotations-4.0.2.Final.jar

hibernate-core-4.2.7.SP1.jar

hibernate-jpa-2.0-api-1.0.1.Final.jar

javassist-3.18.1-GA.jar

jboss-logging-3.1.0.GA.jar

jboss-transaction-api_1.1_spec-1.0.1.Final.jar

hibernate-entitymanager-4.2.7.SP1.jar

当我部署应用程序时,我收到此错误:

> Caused by: org.xml.sax.SAXParseException: cvc-complex-type.3.1: Value
> '2.0' of    attribute 'version' of element 'persistence' is not valid
> with respect to the corresponding attribute use.Attribute 'version'
> has a fixed value of '1.0'.

如果我将持久化版本更改为 1.0,则应用程序可以正常启动。但是我想用JPA 2.0,你能告诉我我做错了什么吗?

PS:我没有做的一件事是我没有将任何 JPA 功能包应用到我的 WAS(版本 7.0.0)。这可能是问题吗?

【问题讨论】:

    标签: java hibernate jpa


    【解决方案1】:

    看起来 WAS 的 JPA 1.0 库(由父类加载器加载)正在尝试读取您的 web 应用程序的 persistence.xml 并被版本混淆。

    根据this post(法语),您必须安装 OSGI 和 JPA 2.0 功能包,或者将您的 persistence.xml 移动到 META-INF 下以外的其他位置,这样 JPA 1.0 库就找不到它。然后,您需要使用另一种方式(以编程方式或通过 Spring)加载您的 persistence.xml

    【讨论】:

    • 谢谢,那篇法语帖子真的很有帮助。
    • 我已经在使用带有 的 Spring (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) 来指定休眠属性。我决定不使用persistence.xml,因为这是从spring 3.1开始的一个特性。这是dz中一篇文章的摘录:Starting with Spring 3.1, this XML file is no longer necessary – the LocalContainerEntityManagerFactoryBean now supports a ‘packagesToScan’ property where the packages to scan for @Entity classes can be specified.全文:[链接]java.dzone.com/articles/persistence-layer-spring-31-0
    猜你喜欢
    • 2014-07-07
    • 2016-07-12
    • 2014-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多