java JBoss 和不同版本的 Hibernate

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4097567/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 04:44:59  来源:igfitidea点击:

JBoss and different versions of Hibernate

javahibernatejbossclassloader

提问by willcodejavaforfood

We are using JBoss 4.2.3 which in turn comes with version 3.2.1.ga of Hibernate. I would like to use Hibernate 3.5.1-FINAL which supports JPA 2.0. I've been trying to make this work by putting my own hibernate jars in my WEB-INF/lib folder and creating my own classloader for my WAR in jboss-web.xml

我们使用的是 JBoss 4.2.3,而 JBoss 4.2.3 又附带了 Hibernate 的 3.2.1.ga 版本。我想使用支持 JPA 2.0 的 Hibernate 3.5.1-FINAL。我一直试图通过将我自己的休眠 jars 放在我的 WEB-INF/lib 文件夹中并在 jboss-web.xml 中为我的 WAR 创建我自己的类加载器来完成这项工作

<jboss-web>
   <loader-repository> 
      com.moo.foo:archive=catalog-archive 
   </loader-repository> 
</jboss-web> 

I've also tried:

我也试过:

<jboss-web>
 <class-loading java2ClassLoadingCompliance="false">
  <loader-repository>
     com.moo.catalog:loader=catalogLoader
     <loader-repository-config>java2ParentDelegation=false</loader-repository-config>
  </loader-repository>
 </class-loading>
</jboss-web>

But I get loads of various issues and this is the exception I'm currently stuck on:

但是我遇到了各种各样的问题,这是我目前遇到的例外情况:

Caused by: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.<init>(java.lang.Class, java.util.ResourceBundle, org.hibernate.validator.MessageInterpolator, java.util.Map, org.hibernate.annotations.common.reflection.ReflectionManager)
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.getDeclaredConstructor(Unknown Source)
    at org.hibernate.cfg.AnnotationConfiguration.applyHibernateValidatorLegacyConstraintsOnDDL(AnnotationConfiguration.java:443)

Since the deadline is looming I thought I'd better ask if it is even possible? :)

由于截止日期迫在眉睫,我想我最好问问它是否可能?:)

回答by Juan Manuel Perez

Maybe too late, but it may help somebody that finds this thread looking for the problem described above about 'Caused by: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator....':

也许为时已晚,但它可能会帮助找到此线程的人寻找上述关于“Caused by: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator....”的问题:

I'm using Jboss 4.2, Hibernate Core 3.6.5, Hibernate Validator 4.1.0, using maven, and I have the same problem. Finally I've solved it adding also this dependency:

我正在使用 Jboss 4.2、Hibernate Core 3.6.5、Hibernate Validator 4.1.0,使用 maven,我遇到了同样的问题。最后我解决了它,还添加了这个依赖项:

    <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-validator-legacy</artifactId>
          <version>4.0.2.GA</version>
    </dependency>

回答by Pascal Thivent

I didn't test this personally, but the following threadmentions two approaches that you could try (yeah, I know, it's about JBoss 5 but it looks like the problem is identical).

我没有亲自对此进行测试,但以下线程提到了您可以尝试的两种方法(是的,我知道,这是关于 JBoss 5,但看起来问题是相同的)。

Option 1

选项1

Disable java2ParentDelegation(your second jboss-web.xml), bundle your Hibernate JARs into your app and add the following properties to your persistence.xml(to "avoid" the issue you're facing):

禁用java2ParentDelegation(您的第二个 jboss-web.xml),将您的 Hibernate JAR 捆绑到您的应用程序中,并将以下属性添加到您的persistence.xml(以“避免”您面临的问题):

<property name="hibernate.validator.apply_to_ddl">false</property>
<property name="hibernate.validator.autoregister_listeners">false</property>

One user reported this didn't work for him.

一位用户报告说这对他不起作用。

Option 2

选项 2

Disable java2ParentDelegation(your second jboss-web.xml), bundle your Hibernate JARs into your app and override the hibernate-validator JARs in common/lib.

禁用java2ParentDelegation(你的第二个的jboss-web.xml)中,捆绑你的Hibernate JAR文件到您的应用程序和重载Hibernate验证器的JARcommon/lib

I'm not able to explain why the hibernate-validator from commons/libstill gets picked.

我无法解释为什么commons/lib仍然选择了 hibernate-validator 。