SpringBoot 1.3.0 support hibernate 5? - java

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?

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.

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

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

Related

spring.datasource.initialize is deprecated

I have a springboot application where I am trying to add following to application.properties file
spring.datasource.initialize=false
When I add this I see a warning as below:
I tried finding out what's the new property that replaces this deprecated property but in vain.
Can anybody help on this!
Having a reference to a migration guide would be great.
In Spring Boot 2.5, 'spring.datasource.initialization-mode' has been depracated as well:
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.5-Release-Notes#SQL-Script-DataSource-Initialization
you should use:
spring.sql.init.mode=always
or
spring.sql.init.mode=never
You can read more at:
https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto.data-initialization
As per the document
Spring Boot automatically creates the schema of an embedded
DataSource. This behaviour can be customized by using the
spring.datasource.initialization-mode property. For instance, if you
want to always initialize the DataSource regardless of its type:
spring.datasource.initialization-mode=always
Look at this migration guide
As per Spring Boot Migration mentioned in Github
Basic DataSource initialization is now only enabled for embedded data
sources and will switch off as soon as you’re using a production
database. The new spring.datasource.initialization-mode (replacing
spring.datasource.initialize) offers more control.
spring.datasource.initialization-mode=always
The property spring.datasource.initialization-mode from Spring boot verion 2.7 and onwards is not any more depracated. It has been completely removed!
So the change into the replacement property spring.sql.init.mode is a must do from now on.
Spring Boot 2.7 changelog
You can use spring.jpa.defer-datasource-initialization. Refer to this Spring Documentation on how to Initialize a Database Using Basic SQL Scripts:
spring.jpa.defer-datasource-initialization=true
spring.sql.init.enabled=true - to initialize database by data.sql script located in application resources
spring.sql.init.enabled=false - to

Spring boot 1.5.4 to 2.0.4 AttributeConverter registered multiple times

I am aware of the following answer:
Hibernate 5.0.11 - AttributeConverter class registered mulitple times
But it isn't solving my problem. I'm upgrading Spring Boot from 1.5.4 to 2.0.4 and I'm getting
AttributeConverter class [class com.foo.CalculationModeConverter] registered multiple times
None of the code around converters has changed during the upgrade. Hibernate is registered at org.hibernate:hibernate-core:5.2.17.Final according to the dependencies task.
All of my converters were annotated with #Converter and entities used #Convert on properties. This seems to now cause a double registration. I removed #Converter and all is well thus far. I still want to find the documentation on when this changed.

Spring - Issue setting dialect in Hibernate JPA Configuration

I'm moving from a Spring Boot 1.5.9 to a normal Spring project.
In application.properties I've added
spring.autoconfigure.exclude[0]=org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration
spring.autoconfigure.exclude[1]=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
spring.autoconfigure.exclude[2]=org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration
spring.autoconfigure.exclude[3]=org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
In application.properties I have a line that defines the dialect I'm using, it worked properly with the autoconfiguration
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl
When I try to run the project with the new configuration class I have org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory', I have the same error with the autoconfiguration if i remove the dialect line.
My way to specify the properties, including the dialect, in the configuration class is the following
private Map<String, String> properties = new HashMap<String, String>();
public HibernateJpaConfig() {
properties.put("hibernate.hbm2ddl.auto", "create-drop");
properties.put("hibernate.ejb.naming_strategy", "org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl");
}
I noticed a warning message that might be my issue
WARN 13292 --- [ restartedMain] 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 I try to replace the second value of the map with one of those I still have the same error.
Please look at this release note of spring boot.
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.4-Release-Notes#naming-strategy
I think problem is in naming_strategy.
SpringNamingStrategy is no longer used as Hibernate 5.1 has removed support for the old NamingStrategy interface. A new SpringPhysicalNamingStrategy is now auto-configured which is used in combination with Hibernate’s default ImplicitNamingStrategy. This should be very close to (if not identical) to Spring Boot 1.3 defaults, however, you should check your Database schema is correct when upgrading.
If you were already using Hibernate 5 before upgrading, you may be using Hibernate’s 5 default. If you want to restore them after the upgrade, set this property in your configuration:
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

Does JBoss7 allow Hibernate 3 xml configuration?

First I excuse if this is a stupid question.
I am trying to deploy my spring application into JBoss 7. Hibernate entities are configured with xml. That means PojoClass.hbm.xml and not annotated.
What I want know simply is, do JBoss 7 or 8 version support only Hibernate (version 3) mapping Annotations (POJO class mappings to database tables)? and no xml configurations ? If it is possible, would you let me have any guidance resource URL please ?
Check out this guide exampling how you can switch from Hibernate 4 to Hibernate 3.
Once you enable Hibernate 3, you only need to set the JBoss Transaction Manager resolving settings.

Hibernate Validator 5 version compatibility with Hibernate 3.5

Is it safe to use the Hibernate Validator 5.0.1 with Hibernate 3.5.4? From what I've read it should not be a problem and I'm not running into any errors so far (i.e. application compiles, runs and tests pass), but I'm not sure if they fit well together.
Related Hibernate & JPA libs (inside /WEB-INF/libs):
hibernate3.jar
hibernate-annotations-3.5.4-Final.jar
hibernate-commons-annotations-3.2.0.Final.jar
hibernate-core-3.5.4-Final.jar
hibernate-entitymanager-3.5.4-Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate-validator-5.0.1.Final.jar
hibernate-validator-annotation-processor-5.0.1.Final.jar
validation-api-1.1.0.Final.jar
FYI:
Tomcat 7.0.39
Spring 3.0.3
PostgreSQL 9.2
Flyway 2.1.1
BoneCP 0.7.1
You should be fine with using Bean Validation 1.1/Hibernate Validator 5.0.1; Hibernate ORM depends on the Bean Validation API only, and BV 1.1 is compatible with BV 1.0.
I recommend to check the Hibernate Validator migration guide to see whether any of the issues listed there might affect you (for instances changes around logging and the usage of Java 6).

Categories

Resources