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

  • 我使用JPA 2.0 facet配置了我的项目。
  • 将所有休眠的“必需” jar和jpa jar添加到了构建中
    路径以及清单条目中。
  • 我关注了这篇文章:Alternate JPA Providers in WebSphereApplication 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.
    
  • 这是我的应用程序的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"/>
    


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

  • antlr-2.7.7.jar

    hibernate-公共注释-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,则应用程序将启动OK。但是我想使用JPA 2.0,您能告诉我我做错了什么吗?

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

    最佳答案

    看起来WAS的JPA 1.0库(由父类加载器加载)正在尝试读取Webapp的persistence.xml并被版本弄糊涂。

    根据this post(法语)的说法,您必须安装OSGI&JPA 2.0 Feature Pack,或者将persistence.xml移到META-INF下,而不是在其他位置,这样JPA 1.0库找不到它。然后,您需要使用替代方式(通过编程方式或通过Spring)加载persistence.xml

    10-04 15:16