Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Websphere JPA Persistence与默认PersistenceProvider不兼容_Jpa_Websphere_Websphere 8 - Fatal编程技术网

Websphere JPA Persistence与默认PersistenceProvider不兼容

Websphere JPA Persistence与默认PersistenceProvider不兼容,jpa,websphere,websphere-8,Jpa,Websphere,Websphere 8,我得到以下错误 [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

我得到以下错误

  [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.
很多人都经历过这个问题。 一,二,三

我浏览了上述链接和其他一些论坛中提供的答案。通常的建议是删除JPA2.0JAR(我不能这么做),并将类加载器作为父类放在最后

除此之外还有别的解决办法吗?比如在my persistence.xml中定义一些属性

我的websphere版本是8.5.5.2

In my persistence.xml    
<provider>org.hibernate.ejb.HibernatePersistence</provider>
在my persistence.xml中
org.hibernate.ejb.HibernatePersistence
=========================更新=======================

我的依赖项是:

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


现在你需要注意这个问题的另一个方面。。。您没有提到您正在尝试使用哪个版本的Hibernate或哪个版本的JPA。但是,WebSphereV8.5.5.2仅限于JPA2.0。如果您试图使用兼容JPA2.1的Hibernate(或EclipseLink,甚至OpenJPA)版本,那么它将不起作用。您将立即遇到类加载问题。而且,这方面没有解决办法。至少不是容器管理的持久性。使用JPA 2.1提供程序,您可能可以获得一些与应用程序管理的持久性相关的东西,但您将受到可用功能的限制。

问题不在于持久性单元,而在于JPA JAR的包装以及容器如何加载它们。您的JPA2.0 jar包装在哪里?它可能需要通过容器或共享库加载,而不是部署在应用程序本身中。我的hibernate-jpa-2.0 jar随EAR文件一起提供。我无法控制从EAR中删除任何jar。您可以随时解压缩EAR并删除jar进行测试。正如您所看到的,我也在使用JPA 2.0.Good。现在我看到了更新,您正在使用JPA2.0。但是,您仍然很可能遇到我在第一段中提到的类加载器冲突。您是否尝试过删除HibernateJPA2.0APIJAR文件?我认为答案是可以接受的。对于将来有相同问题的人:尝试将应用程序标记为父上一个加载程序,并完成上面提供的答案。