8

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.

Entropy
  • 1,219
  • 6
  • 21
  • 45

4 Answers4

12

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)
Parker Wang
  • 367
  • 6
  • 14
  • Here's a gist of the workaround with modifications for Spring https://gist.github.com/jeffsheets/aec3e94870ef903ce7efe33e00563d3c Also, it seems to be working for me without doing the ApplicationsExcludedFromJpaProcesssing step, but maybe just got lucky – Jeff Sheets May 20 '16 at 20:37
  • Hi @Parker Wang Could you explain more about how to use my own `PersistenceProviderResolver` ? – Sara Selim Jun 16 '20 at 10:31
5

Hibernate 4.2.x implements the JPA 2.0 specification, we use that without any problems in WebSphere 8.5.5. We package the Hibernate JARs in our WARs and set the provider attribute in the persistence.xml to org.hibernate.ejb.HibernatePersistence.

Only Hibernate 4.3.x requires JPA 2.1 and won't work with WebSphere 8.5.5.

dunni
  • 43,386
  • 10
  • 104
  • 99
  • So there is no need to change classloader policy to PARENT_LAST? – svlada Apr 18 '15 at 17:45
  • Because in official WAS instructions the suggest to set classloader to PARENT_LAST (item 3 in list) http://www-01.ibm.com/support/knowledgecenter/SSAW57_8.5.5/com.ibm.websphere.nd.doc/ae/tejb_jpa3rdparty.html?cp=SSAW57_8.5.5%2F1-3-6-0-2-0-0-4-0-0&lang=en – svlada Apr 18 '15 at 18:52
  • I am getting CWWJP9991W: openjpa.Runtime: Warn: An error occurred while registering a ClassTransformer with JPAPUnitInfo – svlada May 05 '15 at 11:12
0

I was able to do that using websphere 8.5.5.13 running on Java 8 by making a shared library that contains

  • hibernate-jpa-2.1-api-1.0.2.Final.jar

  • hibernate-core-4.3.11.Final.jar

and everything worked fine with me.

Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498
-1

you should have no problem using your own persistence provider in WebSphere. My suggestion is for you to package a JPA 2.1 provider in your app and try changing the class loader to be parent last. In this case you would not use the default OpenJPA 2.0 provided by WebSphere. Instead you will be using the provider of your choice.

http://www-01.ibm.com/support/knowledgecenter/api/content/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/tejb_jpa3rdparty.html

http://www-01.ibm.com/support/knowledgecenter/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/trun_classload_server.html?cp=SSAW57_8.5.5%2F3-8-2-5-1&lang=en

Hope this helps.

Just another related article from the IBM support portal: http://www-01.ibm.com/support/docview.wss?uid=swg21672354

Wahid
  • 111
  • 6
groo
  • 4,213
  • 6
  • 45
  • 69
  • 2
    From your links: "Java EE applications that use JPA functions can employ third-party persistence providers other than the providers that are included with the application server. Applications can also specify an Apache OpenJPA provider that is a different version than what is included with the application server, as long as the same version of the JPA specification is supported." The op asks for 2.1 and not a 2.0 exchange. Hibernate with 2.0 will work. Hibernate with 2.1 won't. – Udo Held Jun 10 '14 at 11:16