Hibernate“PreInsertEvent.getSource()”NoSuchMethodError

尝试插入时,我收到以下错误:

java.lang.NoSuchMethodError:org.hibernate.event.PreInsertEvent.getSource()Lorg / hibernate / event / EventSource;

由于hibernate jar不兼容,我见过其他人有同样的问题,但我相信我做对了(根据兼容性矩阵 )

这是我的pom.xml中的相关部分:

 org.hibernate hibernate-annotations 3.4.0.GA   org.hibernate hibernate-commons-annotations 3.3.0.ga   org.hibernate hibernate-core 3.3.1.GA   org.hibernate hibernate-validator 3.1.0.GA   org.hibernate hibernate-entitymanager 3.4.0.GA  

任何人都可以建议吗?

问候

马蒂

我找到了一个解决方案,但我不确定它是否正确 – 任何有更好的人,请告知:

添加了对cglib的引用,并且明确排除了hibernate(包括3.2)

    cglib cglib 2.2   commons-lang commons-lang 2.3   org.hibernate hibernate-annotations 3.4.0.GA   org.hibernate hibernate-commons-annotations 3.3.0.ga   org.hibernate hibernate     org.hibernate hibernate-core 3.3.1.GA   org.hibernate hibernate-validator 3.1.0.GA   org.hibernate hibernate-entitymanager 3.4.0.GA   commons-lang commons-lang 2.3   commons-collections commons-collections 3.2.1   

这是一个已知的错误: https : //hibernate.onjira.com/browse/HVAL-81 。 当您引用旧版本的hibernatevalidation器而不是核心时,会发生这种情况。

发生此错误时我遇到的实际问题是

  1. Hibernate核心依赖不在我的EAR包装中。

  2. 默认情况下,它选择了jboss.4.2.3 /…/ lib的hibernate3.jar。

  3. 只需将hibernate-core-3.3.1.GA添加到EAR包中的依赖列表中。

  4. 已经在jboss-app.xml中设置了覆盖器的覆盖。

  5. 从hibernate-entitymanager-3.4.0.GA中排除了hibernate-core(不要认为这是必需的,因为提供的核心将是3.3.0.SP1并且无论如何都将被省略)。

它使用了一些已经存在的xml-apis,ejb3-persistence等的排除,来自hibernate-core的依赖。

最后,核心依赖关系看起来像这样。

   org.hibernate hibernate-core 3.3.1.GA   ejb3-persistence org.hibernate   jta javax.transaction   persistence-api javax.persistence   xml-apis xml-apis    

注意:我不认为cglib是必需的,它与此上下文无关。

希望这对某人有用。