[英]Upgrade Hibernate version in JBOSS
I am having a hard time when trying to ship inside my EAR my own version of Hibernate (and not the one that JBoss brings by default). 我试图在我的EAR中发布我自己的Hibernate版本时遇到困难(而不是JBoss默认带来的版本)。
Then I made my deployment "scoped" by including in the EAR a jboss-app.xml file containing the following: 然后我通过在EAR中包含一个包含以下内容的jboss-app.xml文件来使我的部署成为“作用域”:
<jboss-app>
<loader-repository>
com.example:archive=unique-archive-name
<loader-repository-config>
java2ParentDelegation=false
</loader-repository-config>
</loader-repository>
</jboss-app>
And, as usual, I declare my persistence provider in the persistence unit to be Hibernate, as follows: 并且,像往常一样,我将持久性单元中的持久性提供程序声明为Hibernate,如下所示:
<persistence>
<persistence-unit name="myapp">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
...
But then, the worst happens. 但是,最糟糕的情况发生了。 On deployment, the server throws a ClassCastException when it tries to cast from org.hibernate.ejb.HibernatePersistence to the JPA interface javax.persistence.spi.PersistenceProvider (which IS implimented by HibernatePersistence). 在部署时,服务器在尝试从org.hibernate.ejb.HibernatePersistence转换为JPA接口javax.persistence.spi.PersistenceProvider (由HibernatePersistence表示)时抛出ClassCastException。
This is kind of WEIRD, because I am shipping the JPA API also in my EAR, so, given that the classes of the EAR have priority to those of JBoss, it should have no problem when casting from HibernatePersistence to PersistenceProvider, since they "should be" on the same class loader. 这有点像WEIRD,因为我也在我的EAR中发布JPA API,因此,鉴于EAR的类优先于JBoss的类,从HibernatePersistence转换为PersistenceProvider时应该没有问题,因为它们“应该”是“在同一个班级装载机上。
If I don't ship my own JPA API, then the deployment fails with a ClassNotFoundException when JBoss tries to find some JPA class. 如果我没有发布自己的JPA API,那么当JBoss试图找到一些JPA类时,部署会因ClassNotFoundException而失败。
Any idea on why is this casting failing? 任何关于为什么这个演员失败的想法?
I am using JBoss 5.1.0, and trying to use Hibernate 3.5.6.Final. 我正在使用JBoss 5.1.0,并尝试使用Hibernate 3.5.6.Final。 The JPA API version is the one imported transitively by the menctioned Hibernate version. JPA API版本是由被提取的Hibernate版本传递的版本。
You could try turning on class scoping via the ear deployer. 您可以尝试通过耳部部署来打开课程范围。 For JBoss 5.x edit: 对于JBoss 5.x编辑:
jboss/server/[configuration]/deployers/ear-deployer-jboss-beans.xml 的JBoss /服务器/ [配置] /deployers/ear-deployer-jboss-beans.xml
and change: 并改变:
<bean name="EARClassLoaderDeployer" class="org.jboss.deployment.EarClassLoaderDeployer">
<property name="isolated">false</property>
</bean>
setting isolated to true. 设置隔离为真。
Have you included the hibernate-entitymanager.jar too? 你也包含了hibernate-entitymanager.jar吗?
Otherwise you can try replacing the hibernate core jar in the common/lib with the 3.5.6 version. 否则,您可以尝试使用3.5.6版本替换common / lib中的hibernate核心jar。
To solve the class loading issues with hibernate in jboss server you need to add the jboss-classloading.xml
inside the WEB-INF
folder of your web application. 要解决jboss服务器中hibernate的类加载问题,您需要在Web应用程序的WEB-INF
文件夹中添加jboss-classloading.xml
。 Read more about these configuration settings here . 在此处详细了解这些配置设置。
<classloading xmlns="urn:jboss:classloading:1.0"
domain="pentaho.ear"
export-all="NON_EMPTY"
import-all="true"
parent-first="false">
</classloading>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.