Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring 4.2.3.RELEASE and Hibernate 5.0.4.Final compatibility issue

Has anyone configured Spring 4.2.3.RELEASE and Hibernate 5.0.4.Final together ? Official documents from Spring say from version 4.2 spring starts supporting Hibernate version 5. But in case of configuring them together i always get the following Exception

Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.aop.framework.autoproxy.AutoProxyUtils.determineTargetClass(Lorg/springframework/beans/factory/config/ConfigurableListableBeanFactory;Ljava/lang/String;)Ljava/lang/Class;
at org.springframework.context.event.EventListenerMethodProcessor.afterSingletonsInstantiated(EventListenerMethodProcessor.java:78)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:792)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:838)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at me.shafin.sustord.dao.App.main(App.java:8)

Here is the pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.samples.service.service</groupId>
<artifactId>RokomiMoc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>


<properties>

    <!-- Generic properties -->
    <java.version>1.8</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

    <!-- Web -->
    <jsp.version>2.3.1</jsp.version>
    <jstl.version>1.2</jstl.version>
    <servlet.version>3.1.0</servlet.version>


    <!-- Spring -->
    <spring-framework.version>4.2.3.RELEASE</spring-framework.version>
    <spring-security.version>3.2.5.RELEASE</spring-security.version>

    <!-- Hibernate -->
    <hibernate-framework.version>5.0.4.Final</hibernate-framework.version>

    <!-- Validator -->
    <hibernate.validator.version>5.0.1.Final</hibernate.validator.version>
    <javax.validation.version>1.1.0.Final</javax.validation.version>

    <!-- File upload -->
    <commons-fileupload.version>1.3.1</commons-fileupload.version>

    <!-- Logging -->
    <logback.version>1.0.13</logback.version>
    <slf4j.version>1.7.5</slf4j.version>

    <!-- Test -->
    <junit.version>4.11</junit.version>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>

    <!-- Spring -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-expression</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>


    <!-- View -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>${jstl.version}</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>javax.servlet.jsp-api</artifactId>
        <version>${jsp.version}</version>
    </dependency>


    <!-- Spring security -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>${spring-security.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>${spring-security.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>${spring-security.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-taglibs</artifactId>
        <version>${spring-security.version}</version>
    </dependency>


    <!-- jsr303 validation dependencies -->
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>${javax.validation.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>${hibernate.validator.version}</version>
    </dependency>



    <!-- Hibernate -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>${hibernate-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>${hibernate-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.37</version>
    </dependency>
    <dependency>
        <groupId>c3p0</groupId>
        <artifactId>c3p0</artifactId>
        <version>0.9.1.2</version>
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <groupId>jaxen</groupId>
        <artifactId>jaxen</artifactId>
        <version>1.1.6</version>
    </dependency>


    <!-- Fileupload -->
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>${commons-fileupload.version}</version>
    </dependency>


    <!-- Rest support -->
    <!-- For Spring 4.1.x and above, jackson-databind 2.3 or above is recommended, 
        in order to avoid conversion issues. -->
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.13</version>
    </dependency>


    <!-- Servlet -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>${servlet.version}</version>
    </dependency>


    <!-- Others -->






    <!-- Logging with SLF4J & LogBack -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${slf4j.version}</version>
        <scope>compile</scope>
    </dependency>


    <!-- Test Artifacts -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring-framework.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
        <version>2.5.2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.annotation</groupId>
        <artifactId>jsr250-api</artifactId>
        <version>1.0</version>
        <scope>provided</scope>
    </dependency>





    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>4.2.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>com.sun.mail</groupId>
        <artifactId>javax.mail</artifactId>
        <version>1.5.4</version>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>4.2.3.RELEASE</version>
    </dependency>
</dependencies>

This pom.xml and my other configurations are quite okay with Spring 4.0.6 and Hibernate 4.3.6 ... Can anyone please share his/her experience with these latest version compatibility issues. Or is there anything new way to configure them together that I am missing ?

like image 797
Shafin Mahmud Avatar asked Dec 02 '15 21:12

Shafin Mahmud


People also ask

Which Hibernate version is compatible with Spring 4?

Note that Hibernate 4.3 is a JPA 2.1 provider and therefore only supported as of Spring Framework 4.0.

Which Hibernate version is compatible with Spring 5?

Spring 5x is compatible with hibernate 4x unless you are using it as an implementation of JPA which might not be compatible. A suggestion would be using the latest hibernate.

Which Hibernate version is compatible with Java 17?

Hibernate Validator versions 7.0 6.2 are also compatible with Java 17.

Which Hibernate version is compatible with Java 11?

Hibernate 5.3 lists Java 11 as supported in the latest release 5.3. 22. Moreover, Hibernate 5.6 is also Java 11 compatible.


2 Answers

I was dealing with same problem for a few hours. I have noticed that :

[INFO] +- org.springframework.security:spring-security-core:jar:4.0.3.RELEASE:compile
[INFO] |  +- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  \- org.springframework:spring-aop:jar:4.2.2.RELEASE:compile

This shows that lastest spring-security-core version 4.0.3.RELEASE is dependent with Spring Framework 4.2.2.RELEASE.

You have two solution for this:

1) Exclude spring-aop 4.2.2 for spring-security-core and explicitly add your dependency description for spring-aop:jar:4.2.3.RELEASE to your pom file.

2) Change your 4.2.3.RELEASE dependency to 4.2.2.RELEASE and change Hibernate version 5.0.4.Final to 5.0.2.Final

I choose second way and it worked for me.

like image 82
Ekrem Kucuk Avatar answered Oct 12 '22 23:10

Ekrem Kucuk


Looking at the pom.xml of spring-orm-4.2.3.RELEASE, the version of the hibernate that it is using is 5.0.3.Final

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-core</artifactId>
  <version>5.0.3.Final</version>
  <scope>compile</scope>
  <optional>true</optional>
</dependency>

It is an optional dependency, so it will not be resolved as a transitive dependency. You still need to provide the necessary hibernate jars like what you are currently doing. You only need to modify the version to the official version that it is using.

<hibernate-framework.version>5.0.3.Final</hibernate-framework.version>
like image 34
Bnrdo Avatar answered Oct 13 '22 00:10

Bnrdo