java.lang.ClassNotFoundException: org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper

后端 未结 2 333
遇见更好的自我
遇见更好的自我 2021-01-13 08:46

During the validation of entity (before insertion) on my Spring MVC app I get the following error :

    ...
    at io.undertow.server.Connectors.executeRoot         


        
相关标签:
2条回答
  • 2021-01-13 09:23

    The error mentioned is occurring due to a possible clash of dependency versions.

    WildFly already provides both hibernate-core and hibernate-validator dependencies in <wildfly_dir>\modules\system\layers\base\org\hibernate.

    In the case of WildFly10, the dependencies' versions are the following:

    • hibernate-core-5.0.7.Final
    • hibernate-validator-5.2.3.Final

    Therefore, on your pom.xml, you could place your Hibernate dependencies as provided and let the container use its own:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.1.0.Final</version>
        <scope>provided</scope>
    </dependency>
    
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>5.2.4.Final</version>
        <scope>provided</scope>
    </dependency>
    

    But if you want to provide your own dependencies, as mentioned on WildFly 10 documentation, you should provide a jboss-deployment-structure.xml, where you basically tell WildFly to disregard it's own dependencies:

    <jboss-deployment-structure>
        <deployment>
            <exclusions>
                <module name="org.hibernate" slot="main" />
            </exclusions>
        </deployment>
    </jboss-deployment-structure>
    

    This way, the container will load the dependencies that were packaged with your application and that are present on your WAR's WEB-INF/lib folder.

    EDIT

    After going to the source code of PersistenceUtilHelper.isLoadedWithoutReference, one notices that, in Hibernate 5.1, it no longer references the class FieldInterceptionHelper, on line 119, where the error occurs. Whereas in the version 5.0 it still does.

    I also suggest you to add the most recent version of the hibernate-entitymanager dependency, in order to be in accordance with the other Hibernate dependencies:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.1.0.Final</version>
    </dependency>
    
    0 讨论(0)
  • 2021-01-13 09:34

    The following worked for me:

    hibernate-core-5.1.0.Final
    hibernate-entitymanager-5.1.0.Final
    hibernate-validator-5.2.4.Final
    
    0 讨论(0)
提交回复
热议问题