Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

hibernate - Websphere 8.5 with JPA 2.1

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...