Nick's Tech Blog: java.lang.ClassCastException: com.ibm.websphere.persistence.PersistenceProviderImpl incompatible with javax.persistence.spi.PersistenceProvider

Pages

Thursday, June 9, 2011

java.lang.ClassCastException: com.ibm.websphere.persistence.PersistenceProviderImpl incompatible with javax.persistence.spi.PersistenceProvider

Problem

Received the following stacktrace from Websphere7.

Caused by: java.lang.ClassCastException: com.ibm.websphere.persistence.PersistenceProviderImpl incompatible with javax.persistence.spi.PersistenceProvider
        at javax.persistence.Persistence$1.isLoaded(Persistence.java:77)
        at org.hibernate.validator.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:62)
        at org.hibernate.validator.engine.resolver.DefaultTraversableResolver.isReachable(DefaultTraversableResolver.java:94)
        at org.hibernate.validator.engine.resolver.SingleThreadCachedTraversableResolver.isReachable(SingleThreadCachedTraversableResolver.java:47)
        at org.hibernate.validator.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:757)
        ... 77 more



Solution

  1. Remove hibernate-jpa-2.0-api-1.0.0.Final.jar from your war file, and add it as a shared library to your application. 
  2. Make sure you restart your application.
N.B. You shouldn't need to do this if you've setup the shared library correctly, but if you're still having trouble, it might help if you have the following classloading strategy enabled - Classes loaded with local class loader first (parent last)

See:
Configuring persistence provider support in the application server - http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.zseries.doc/info/zseries/ae/tejb_configpp.html
Creating shared libraries - http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.zseries.doc/info/zseries/ae/tcws_sharedlib_create.html
Associating shared libraries with applications or modules - http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.zseries.doc/info/zseries/ae/tcws_sharedlib_app.html
Configuring class loaders of a server - http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.zseries.doc/info/zseries/ae/trun_classload_server.html

4 comments:

  1. This solution hasn't seemed to work for me. I have setup a shared library as per your suggestion, removed the library from my WAR and also set the classloader policy to PARENT_LAST and still get the same exception. Could you share information such as your persistence.xml or anything else which may have contributed to you fixing the issue? Thanks Steve

    ReplyDelete
  2. By way of an update, installation of the 1.0.0.3: WebSphere Application Server V7 Feature Pack for OSGi and JPA (http://www-01.ibm.com/support/docview.wss?uid=swg24029077) resolved the issue for us, without having to alter classloader policies.

    ReplyDelete
  3. Thanks Steve, much appreciated for the comment! Sounds like a much better solution. Hopefully that helps the next person.

    ReplyDelete
  4. Thank You and I have a swell supply: What To Expect When Renovating A House house renovation shows

    ReplyDelete