9

I create a skeleton application use Spring boot. This is my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>com.lynas</groupId>
    <artifactId>SpringMVCHibernate</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>SpringMVCHibernate</name>
    <description>SpringMVCHibernate</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.2.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.1.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

I stuck at this step:

Spring Boot: The managed version is 1.3.2.RELEASE The artifact is managed in org.springframework.boot:spring-boot-dependencies:1.3.2.RELEASE

enter image description here

When I try add Hiberante 5.1.0.Final manually, this notice appear:

Overriding managed version 4.3.11.Final for hibernate-core

enter image description here

Help me resolve these problem.

Vy Do
  • 46,709
  • 59
  • 215
  • 313

3 Answers3

23

Spring Boot provides dependency management for Hibernate. The warning is Eclipse telling you that you've overridden this dependency management by declaring a version directly on a dependency. That's a risky thing to do as you may end up with a mixture of Hibernate versions on the classpath. In fact, looking at your pom, you've overridden the version of hibernate-core but not of hibernate-entitymanager. This means you'll have 5.1.0.Final of the former and 4.3.11.Final of the latter on the classpath. That will almost certainly lead to problems at runtime.

A safer way to use Hibernate 5 is to override Boot's dependency management. As you are using spring-boot-starter-parent as your pom's parent you can do that by overriding the hibernate.version property:

<properties>
    <hibernate.version>5.1.0.Final</hibernate.version>
</properties>

This will ensure that all Hibernate modules for which Spring Boot provides dependency management will have the desired version.

Finally, a note of caution. Hibernate 5.1 is very new and contains some breaking changes, even from 5.0.x. As a result, you may run into some incompatibility problems. If you don't want to be right on the bleeding edge, 5.0.x may be a safer choice. It will become the default Hibernate version in Spring Boot 1.4.

Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
  • 3
    Any suggestions for how to do this with Gradle? – Snekse Oct 28 '16 at 19:57
  • I am wondering where can I find the list to find the property names I could overwrite as ``? There must be a list somewhere I could not find yet. – Michael Hegner May 14 '19 at 13:21
  • There are defined in the `spring-boot-dependencies` pom which is the parent of `spring-boot-starter-parent`. Your IDE should allow you to navigate to the pom to view its contents. Failing that, you can find the source on GitHub. Here's the 2.1.5 version, for example: https://github.com/spring-projects/spring-boot/blob/b5d19b798eca7a6400a97e80d42601e027789aa6/spring-boot-project/spring-boot-dependencies/pom.xml#L37-L197 – Andy Wilkinson May 15 '19 at 10:16
  • how to I get similar warning in intellij ide, I recently started using – PKK Aug 19 '21 at 10:19
7

Spring Boot automatically defines version for dependencies as listed in this appendix. http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#appendix-dependency-versions

Eclipse is just reminding about it. You can ignore the warning if you really want to change the version for that dependency.

Update:

See Andy's answer: https://stackoverflow.com/a/35385268/1433665

Community
  • 1
  • 1
TheKojuEffect
  • 20,103
  • 19
  • 89
  • 125
  • 1
    Follow your answer and referred link, latest version of `hibernate-core` is 5.1.0.Final, default version in Spring Boot, is 4.3.11.Final. Is this drawback of Spring Boot? – Vy Do Feb 13 '16 at 14:15
  • 1
    This is feature and huge selling point of Spring Boot. You get well tested and stable matrix of dependencies, but you don't get always bleeding edge stuff in this matrix. If you want to use newer dependencies, you can override default Spring Boot versions. – luboskrnac Feb 13 '16 at 14:20
  • 1
    @dovy There is an github issue in Spring boot to support Hibernate 5. https://github.com/spring-projects/spring-boot/issues/2763 – TheKojuEffect Feb 13 '16 at 15:27
  • 1
    The warning shouldn't be ignored. With the current configuration there will be a mixture of Hibernate versions on the classpath – Andy Wilkinson Feb 13 '16 at 21:04
  • @AndyWilkinson Thanks for letting me know. Your answer fixed an issue I was having with multiple hibernate jar in generated war. Thanks! – TheKojuEffect Feb 16 '16 at 04:19
0

In addition to the answers above. My issue was an old version of STS/Eclipse. After reinstalling with the latest and greatest Spring Tools the error was resolved. https://spring.io/tools

Nelda.techspiress
  • 643
  • 12
  • 32