简体   繁体   English

在JBOSS中升级Hibernate版本

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

相关问题 更新版本Hibernate Jboss Ejb和Java - Update version Hibernate Jboss Ejb and Java 在 Jboss 服务器 (WildFly 18.x) 中将 Hibernate 从 3 升级到 4 - Upgrade Hibernate from 3 to 4 inside Jboss server (WildFly 18.x) Hibernate 从版本 3.0 升级到 3.6 - Upgrade of Hibernate from version 3.0 to 3.6 在jboss 6.0.0 AS上将Hibernate 3.6升级到hibernate 4.3.6,获取java.lang.NoClassDefFoundError:org / hibernate / classic / Session - Upgrade Hibernate 3.6 to hibernate 4.3.6 on jboss 6.0.0 AS getting java.lang.NoClassDefFoundError: org/hibernate/classic/Session 将Maven升级到Spring 4.1.6版本时,Maven更新休眠吗? - Maven updating hibernate when upgrade spring to spring 4.1.6 version? 从Spring 2.5.6升级到3.2.6导致Spring事务管理在JBoss 5.1.0和Hibernate 3.5.6上不再起作用 - Upgrade from Spring 2.5.6 to 3.2.6 caused Spring Transaction Management to no longer work on JBoss 5.1.0 and Hibernate 3.5.6 EJB升级到JBoss AS 7时出错 - Error on EJB upgrade to JBoss AS 7 升级到JBoss 7数据源不起作用 - Upgrade to JBoss 7 Datasource is Not Working JBoss 3.2.2和JDBC升级 - JBoss 3.2.2 and JDBC upgrade Java版本从7升级到8时出现的问题:org.jboss.classfilewriter.InvalidBytecodeException:无法将变量加载为0 - Issue when java version upgrade from 7 to 8 : org.jboss.classfilewriter.InvalidBytecodeException: Cannot load variable at 0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM