6

I am getting the following error

  [9/29/15 21:06:33:816 IST] 0000003f JPAPUnitInfo  E   CWWJP0015E: An error  occurred in the 
org.hibernate.ejb.HibernatePersistence persistence provider when it attempted  to create the
container entity manager factory for the rga-hibernate-jpa persistence unit. 
The following error occurred: 
java.lang.ClassCastException: org.hibernate.ejb.HibernatePersistence 
incompatible with javax.persistence.spi.PersistenceProvider.

This problem has been experienced by lot of people. 1.this,2.this,3.and this

I went through the answers provided in the above links and some other forums. The common suggestion is to remove the JPA 2.0 jar (which I can't do) and to make the class loader as parent last.

Is there any solution other than this? Like defining some properties in my persistence.xml.

My websphere version is 8.5.5.2.

In my persistence.xml    
<provider>org.hibernate.ejb.HibernatePersistence</provider>

===================UPDATE=======================

My dependencies are: My dependency

Community
  • 1
  • 1
Vivek Agrawal
  • 617
  • 11
  • 23
  • The issue isn't with the persistence unit, but with the packaging of the JPA jars and how they are loaded by the container. Where is your JPA 2.0 jar packaged? It likely needs to be loaded by the container or though shared libraries and not deployed within the application itself. – Chris Sep 30 '15 at 17:12
  • my hibernate-jpa-2.0 jar is shipped with the EAR file. I don't have control to remove any jars from the EAR. – Vivek Agrawal Oct 01 '15 at 04:52
  • You can always unzip ear and remove jar for test. – Gas Oct 01 '15 at 07:23

1 Answers1

10

As described in the other postings you referenced, the basic issue is that you have more than one copy of the javax.persistence API in your system. Most likely, you have one in your application (along with Hibernate impl) and one provided by the WebSphere Application Server. Since modifying WebSphere is going to be next to impossible, I would suggest exploring the removal of the Hibernate JPA API jar file.

Now there is another aspect of this issue that you need to be aware of... You don't mention which version of Hibernate nor which version of JPA you are attempting to use. But, WebSphere v8.5.5.2 is limited to JPA 2.0. If you are trying to use a version of Hibernate (or EclipseLink or even OpenJPA) that is JPA 2.1 compliant, it's not going to work. You will encounter classloading issues immediately. And, there is no workaround for this. At least not with container-managed persistence. You might be able to get something to work with application-managed persistence with a JPA 2.1 provider, but you'll be limited on the functionality available to you.

Kevin S
  • 211
  • 2
  • 2
  • as you can see I am also using JPA 2.0. – Vivek Agrawal Oct 01 '15 at 05:13
  • Good. I see the update now that you are using JPA 2.0. But, you are still most likely hitting the classloader conflicts as mentioned in my first paragraph. Have you tried removing the hibernate JPA 2.0 API jar file? – Kevin S Oct 01 '15 at 15:20
  • 1
    I am marking the answer as acceptable. For people having same problem in the future: Try to mark the application as Parent Last Loader and go through the answer provided above. – Vivek Agrawal Oct 05 '15 at 06:45