Websphere JPA Persistence 与默认的 PersistenceProvider 不兼容

Websphere JPA Persistence is incompatible with default PersistenceProvider

我收到以下错误

  [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.

很多人都遇到过这个问题。 1.this,2.this,3.and this

我查看了上述链接和其他一些论坛中提供的答案。常见的建议是删除 JPA 2.0 jar(我不能这样做)并将 class 加载器作为父加载器。

除了这个还有什么解决办法吗?就像在我的 persistence.xml.

中定义一些属性

我的websphere版本是8.5.5.2。

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

===================更新=======================

我的依赖项是:

如您引用的其他帖子所述,基本问题是您的系统中有多个 javax.persistence API 副本。最有可能的是,您的应用程序中有一个(连同 Hibernate impl),另一个由 WebSphere Application Server 提供。由于修改 WebSphere 几乎是不可能的,我建议探索删除 Hibernate JPA API jar 文件。

现在您需要注意此问题的另一个方面...您没有提及您尝试使用哪个版本的 Hibernate 或哪个版本的 JPA。但是,WebSphere v8.5.5.2 仅限于 JPA 2.0。如果您尝试使用与 JPA 2.1 兼容的 Hibernate 版本(或 EclipseLink 甚至 OpenJPA),它将无法工作。您将立即遇到类加载问题。而且,没有解决方法。至少不是容器管理的持久性。您可能能够通过 JPA 2.1 提供程序获得一些与应用程序管理的持久性一起工作的东西,但是您可以使用的功能将受到限制。