Hibernate “PreInsertEvent.getSource()” NoSuchMethodError

前端 未结 3 686
执念已碎
执念已碎 2020-12-20 00:28

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

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

相关标签:
3条回答
  • 2020-12-20 00:43

    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).

    It worked with some exclusions of some already existing xml-apis, ejb3-persistence, etc. dependecies from the 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.

    Hope this is useful for someone.

    0 讨论(0)
  • 2020-12-20 00:45

    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)

     <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>
    
    0 讨论(0)
  • 2020-12-20 00:54

    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.

    0 讨论(0)
提交回复
热议问题