Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Websphere JPA Persistence is incompatible with default PersistenceProvider

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

like image 231
Vivek Agrawal Avatar asked Sep 30 '15 15:09

Vivek Agrawal


1 Answers

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.

like image 98
Kevin S Avatar answered Sep 24 '22 02:09

Kevin S