java 休眠“PreInsertEvent.getSource()” NoSuchMethodError

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/882338/
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-29 14:13:14  来源:igfitidea点击:

Hibernate "PreInsertEvent.getSource()" NoSuchMethodError

javahibernatemaven-2

提问by Marty Pitt

I'm recieving the following error when trying to do inserts:

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

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

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

I've seen otherpeople with the same problem due to incompatibility in hibernate jars, but I believe I've got it right (according to the compatibility matrix)

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

Here's the relevant section from my pom.xml:

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

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-annotations</artifactId>
        <version>3.4.0.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>3.3.0.ga</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.3.1.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>3.1.0.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.4.0.GA</version>
    </dependency>

Can anyone advise?

任何人都可以建议吗?

Regards

问候

Marty

马蒂

回答by Marty Pitt

I found a solution, but I'm not sure it's correct -- anyone with a better, please advise:

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

Added a reference to cglib, and explicity excluded hibernate (was including 3.2)

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

 <dependencies>
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2</version>
    </dependency>
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-annotations</artifactId>
        <version>3.4.0.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>3.3.0.ga</version>
        <exclusions>
            <exclusion>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.3.1.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>3.1.0.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.4.0.GA</version>
    </dependency>

    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.2.1</version>
    </dependency>
</dependencies>

回答by phillip.darley

This is a known bug : https://hibernate.onjira.com/browse/HVAL-81. It occurs when you reference an older version of hibernate validator than core.

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

回答by raksja

The actual problem for me when this error occurred is

发生此错误时对我来说的实际问题是

  1. Hibernate-core dependency was not in my EAR packaging.

  2. By default it was picking the jboss.4.2.3/.../lib's hibernate3.jar.

  3. Just adding hibernate-core-3.3.1.GA to my dependencies list in EAR packaging.

  4. Already had the overriding of loaders set in jboss-app.xml.

  5. Excluded the hibernate-core from hibernate-entitymanager-3.4.0.GA (don't think this is required as the core supplied will be 3.3.0.SP1 and will be omitted anyhow).

  1. Hibernate-core 依赖项不在我的 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,无论如何都会被省略)。

It worked with some exclusions of some already existing xml-apis, ejb3-persistence, etc. dependecies from the hibernate-core.

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

Finally the core dependency looked like this.

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

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.3.1.GA</version>
          <exclusions>
            <exclusion>
                <artifactId>ejb3-persistence</artifactId>
                <groupId>org.hibernate</groupId>
            </exclusion>
            <exclusion>
                <artifactId>jta</artifactId>
                <groupId>javax.transaction</groupId>
            </exclusion>
            <exclusion>
                <artifactId>persistence-api</artifactId>
                <groupId>javax.persistence</groupId>
            </exclusion>
            <exclusion>
                <groupId>xml-apis</groupId>
                <artifactId>xml-apis</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

Note: I don't think cglib is required is its not relevant to this context.

注意:我认为不需要 cglib 是因为它与此上下文无关。

Hope this is useful for someone.

希望这对某人有用。