SpringBoot 1.3.0 support hibernate 5?
Asked Answered
D

3

15

I'm a little confused about SpringBoot's (1.3.0) support of Hibernate5. The reference lists a dependency on hibernate 4.3.11.Final but it also lists a dependency on SpringFramework 4.2.3 which includes Hibernate5 support.

Is it just a matter of adding the extra Hibernate5 dependencies to override what Boot bundles? Can someone please clarify for me?

Dett answered 6/12, 2015 at 23:26 Comment(0)
B
16

You can use either Hibernate 4.3 or Hibernate 5.0 with Spring Boot 1.3. As you've observed, Hibernate 4.3.x is the default version.

To use Hibernate 5.0 you should override the hibernate.version property in Spring Boot's dependency management. Assuming that you're using Maven:

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

When using Hibernate 5.0, the one big difference from using Hibernate 4.3.x is that you'll lose Spring Boot's custom naming strategy. Due to a breaking change made in Hibernate 5.0, you'll see a warning like this logged at startup:

2015-12-07 10:04:56.911  WARN 81371 --- [           main] org.hibernate.orm.deprecation            : HHH90000006: Attempted to specify unsupported NamingStrategy via setting [hibernate.ejb.naming_strategy]; NamingStrategy has been removed in favor of the split ImplicitNamingStrategy and PhysicalNamingStrategy; use [hibernate.implicit_naming_strategy] or [hibernate.physical_naming_strategy], respectively, instead.

If you dislike Hibernate 5's defaults, you can specify a custom implicit or physical naming strategy in Spring Boot's application.properties using the spring.jpa.properties.hibernate.implicit_naming_strategy and spring.jpa.properties.hibernate.physical_naming_strategy properties respectively.

Bharat answered 7/12, 2015 at 10:15 Comment(1)
Thanks for the detailed answer, however excuse my ignorance, could you elaborate on how I can migrate to hibernate 5 without breaking anything that already exists? Is there a naming strategy that substitutes the one we're currently using org.hibernate.cfg.ImprovedNamingStrategy? Or maybe its a better decision to hold back on Hibernate 5 at the moment until Spring boot officially migrates?Onfroi
F
6

Update July 2016: With the release of Spring Boot 1.4.0 the default Hibernate 5 is used as the default JPA persistence provider.


There is a ticket about migrating to Hibernate 5 for some time now - it seems the main setback is some name strategy incompatibility. Asof now, the ticket is currently scheduled for 1.4.0

Foe answered 7/12, 2015 at 0:16 Comment(1)
1.4.0 is now released with Hibernate 5 being the default JPA persistence provider. github.com/spring-projects/spring-boot/wiki/…Trike
V
-1

Thanks guys! after many trials, this solution worked for me like a charm! I implemented custom strategy and set them in application.yml as shown below:

   jpa:
    database: MYSQL
    database-platform: org.hibernate.dialect.MySQL5Dialect
    properties:
        hibernate:
            implicit_naming_strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl
            physical_naming_strategy: com.quicken.ups.entities.utils.DBFieldNamingStrategy
Villiers answered 19/4, 2016 at 14:53 Comment(1)
Where could i find the code for : com.quicken.ups.entities.utils.DBFieldNamingStrategy ?Anishaaniso

© 2022 - 2024 — McMap. All rights reserved.