Websphere 8.5与JPA 2.1 [英] Websphere 8.5 with JPA 2.1

查看:398
本文介绍了Websphere 8.5与JPA 2.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IBM过去有一个功能包可以将JPA 2.0加入到WAS 7中.WAS 8.5.5显然带有JPA 2.0。但是我们有一个我们刚刚升级到Hibernate 4的应用程序,它需要JPA 2.1。我无法找到将WAS 8.5功能包推送到JPA 2.1的链接。

其他人在WAS 8.5中使用过Hibernate 4吗?如果是这样,怎么样?没有功能包,我们就得到了javax.persistence类的NoSuchMethodError。

解决方案

Hibernate 4.3.7.Final 可以在Websphere Application Server 8.5.5 中使用,具有以下配置:


  • code> hibernate-jpa-2.1.jar ,并将classloader策略设置为PARENT_LAST。

    Hibernate 4.3.7.Final与Websphere 8.5.5提供的JPA 2.0 API不兼容。

  • 设置JVM属性 com.ibm.websphere.persistence.ApplicationsExcludedFromJpaProcessing = * 可禁用Websphere JPA初始化。



    这将在启动期间获得以下 SAXParseException ,因为Websphere会根据JPA 2.0架构尝试解析persistence.xml。


  • ul>

     
    导致:org.xml.sax.SAXParseException:expec ted根元素{http://java.sun.com/xml/ns/persistence}persistence
    at com.ibm.ws.jpa.management.JaxbUnmarshaller.startElement(JaxbUnmarshaller.java:310)




    • 应用解决JPA-4问题



      使用Hibernate的JPA 2 API代替Webspheres JPA 1 API报告问题,而解决方法也适用于Hibernate的JPA 2.1 API,并进行了一些小的更改: / p>

      您需要将 HibernatePersistence 替换为 HibernatePersistenceProvider 已被弃用。

      如果没有这个,您将在启动过程中获得 ClassCastException ,因为Hibernate的JPA 2.1 API将加载所有 PersistenceProvider 类,包括在classpath中公开的Websphere类。




     
    导致:java.lang.ClassCastException:com.ibm.websphere.persistence.PersistenceProviderImpl与javax.persistence.spi.PersistenceProvider不兼容$ b $ javax.persistence.Persistence $ 1.isLoaded(Persistence.java:110)
    at org.hibernate.validator.internal.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:56)


    IBM used to have a feature pack to put JPA 2.0 into WAS 7. WAS 8.5.5 evidently comes with JPA 2.0. But we have an app we just upgraded to Hibernate 4, which needs JPA 2.1. I can't find a link for a WAS 8.5 feature pack to push to JPA 2.1.

    Has anyone else used Hibernate 4 in WAS 8.5? If so, how? Without a feature pack, we get NoSuchMethodError on javax.persistence classes.

    解决方案

    Hibernate 4.3.7.Final can be used in Websphere Application Server 8.5.5 with following configuration:

    • Pack hibernate-jpa-2.1.jar in your application and set classloader policy to PARENT_LAST.

      Hibernate 4.3.7.Final is not compatible with the JPA 2.0 API provided by Websphere 8.5.5

    • Set JVM property com.ibm.websphere.persistence.ApplicationsExcludedFromJpaProcessing=* to disable Websphere JPA initialization.

      Without this you will get following SAXParseException during startup as Websphere attempts to parse the persistence.xml according to JPA 2.0 schema.

    Caused by: org.xml.sax.SAXParseException: expected root element {http://java.sun.com/xml/ns/persistence}persistence
            at com.ibm.ws.jpa.management.JaxbUnmarshaller.startElement(JaxbUnmarshaller.java:310)
    

    • Apply the work around for issue JPA-4 in your application.

      The issue was reported for using Hibernate's JPA 2 API instead of Webspheres JPA 1 API, while the work around is also applicable to Hibernate's JPA 2.1 API with some minor changes:

      You need to replace HibernatePersistence with HibernatePersistenceProvider as the former has been deprecated.

      Without this you will get following ClassCastException during startup as Hibernate's JPA 2.1 API will load all PersistenceProvider classes, including the Websphere one exposed in classpath.

    Caused by: java.lang.ClassCastException: com.ibm.websphere.persistence.PersistenceProviderImpl incompatible with javax.persistence.spi.PersistenceProvider
            at javax.persistence.Persistence$1.isLoaded(Persistence.java:110)
            at org.hibernate.validator.internal.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:56)
    

    这篇关于Websphere 8.5与JPA 2.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆