Upgrade to Hibernate 6.1.1.Final

This commit makes the following potentially breaking changes:

- Dependency management for modules that do not exist in Hibernate
  6.1 has been removed.
- Hibernate's modules are now in the org.hibernate.orm group. Users
  not using the starter or using modules that are not in the starter
  will have to update their build configuration accordingly.
- spring.jpa.hibernate.use-new-id-generator-mappings has been removed
  as Hibernate no longer supports switching back to the old ID
  generator mappings.

Co-authored-by: Andy Wilkinson <wilkinsona@vmware.com>

Closes gh-31674
This commit is contained in:
Oliver Drotbohm 2022-07-09 14:43:25 +02:00 committed by Andy Wilkinson
parent beb40eaaf6
commit b10c57551c
15 changed files with 32 additions and 68 deletions

View File

@ -107,7 +107,7 @@ dependencies {
exclude group: "commons-logging", module: "commons-logging"
}
optional("org.flywaydb:flyway-core")
optional("org.hibernate:hibernate-core-jakarta")
optional("org.hibernate.orm:hibernate-core")
optional("org.hibernate.validator:hibernate-validator")
optional("org.influxdb:influxdb-java")
optional("org.liquibase:liquibase-core") {

View File

@ -102,10 +102,8 @@ dependencies {
optional("org.flywaydb:flyway-core")
optional("org.flywaydb:flyway-sqlserver")
optional("org.freemarker:freemarker")
optional("org.hibernate:hibernate-core-jakarta")
optional("org.hibernate:hibernate-jcache") {
exclude group: "org.hibernate", module: "hibernate-core"
}
optional("org.hibernate.orm:hibernate-core")
optional("org.hibernate.orm:hibernate-jcache")
optional("org.hibernate.validator:hibernate-validator")
optional("org.influxdb:influxdb-java")
optional("org.jooq:jooq") {

View File

@ -53,13 +53,6 @@ public class HibernateProperties {
*/
private String ddlAuto;
/**
* Whether to use Hibernate's newer IdentifierGenerator for AUTO, TABLE and SEQUENCE.
* This is actually a shortcut for the "hibernate.id.new_generator_mappings" property.
* When not specified will default to "true".
*/
private Boolean useNewIdGeneratorMappings;
public String getDdlAuto() {
return this.ddlAuto;
}
@ -68,14 +61,6 @@ public class HibernateProperties {
this.ddlAuto = ddlAuto;
}
public Boolean isUseNewIdGeneratorMappings() {
return this.useNewIdGeneratorMappings;
}
public void setUseNewIdGeneratorMappings(Boolean useNewIdGeneratorMappings) {
this.useNewIdGeneratorMappings = useNewIdGeneratorMappings;
}
public Naming getNaming() {
return this.naming;
}
@ -97,7 +82,6 @@ public class HibernateProperties {
private Map<String, Object> getAdditionalProperties(Map<String, String> existing, HibernateSettings settings) {
Map<String, Object> result = new HashMap<>(existing);
applyNewIdGeneratorMappings(result);
applyScanner(result);
getNaming().applyNamingStrategies(result);
String ddlAuto = determineDdlAuto(existing, settings::getDdlAuto);
@ -114,15 +98,6 @@ public class HibernateProperties {
return result;
}
private void applyNewIdGeneratorMappings(Map<String, Object> result) {
if (this.useNewIdGeneratorMappings != null) {
result.put(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, this.useNewIdGeneratorMappings.toString());
}
else if (!result.containsKey(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS)) {
result.put(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
}
}
private void applyScanner(Map<String, Object> result) {
if (!result.containsKey(AvailableSettings.SCANNER) && ClassUtils.isPresent(DISABLED_SCANNER_CLASS, null)) {
result.put(AvailableSettings.SCANNER, DISABLED_SCANNER_CLASS);

View File

@ -1100,6 +1100,15 @@
"name": "spring.groovy.template.suffix",
"defaultValue": ".tpl"
},
{
"name": "spring.jpa.hibernate.use-new-id-generator-mappings",
"type": "java.lang.Boolean",
"description": "Whether to use Hibernate's newer IdentifierGenerator for AUTO, TABLE and SEQUENCE. This is actually a shortcut for the \"hibernate.id.new_generator_mappings\" property. When not specified will default to \"true\".",
"deprecation": {
"level": "error",
"reason": "Hibernate no longer supports disabling the use of new ID generator mappings."
}
},
{
"name": "spring.http.converters.preferred-json-mapper",
"type": "java.lang.String",

View File

@ -93,19 +93,6 @@ class HibernatePropertiesTests {
}));
}
@Test
void useNewIdGeneratorMappingsDefault() {
this.contextRunner.run(assertHibernateProperties((hibernateProperties) -> assertThat(hibernateProperties)
.containsEntry(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true")));
}
@Test
void useNewIdGeneratorMappingsFalse() {
this.contextRunner.withPropertyValues("spring.jpa.hibernate.use-new-id-generator-mappings:false")
.run(assertHibernateProperties((hibernateProperties) -> assertThat(hibernateProperties)
.containsEntry(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "false")));
}
@Test
void scannerUsesDisabledScannerByDefault() {
this.contextRunner.run(assertHibernateProperties((hibernateProperties) -> assertThat(hibernateProperties)

View File

@ -4,7 +4,8 @@ databaseChangeLog:
author: dsyer
changes:
- createSequence:
sequenceName: hibernate_sequence
sequenceName: city_seq
incrementBy: 50
- createTable:
tableName: city
columns:

View File

@ -1,4 +1,4 @@
CREATE SEQUENCE HIBERNATE_SEQUENCE;
CREATE SEQUENCE city_seq INCREMENT BY 50;
CREATE TABLE CITY (
id BIGINT GENERATED BY DEFAULT AS IDENTITY,

View File

@ -353,22 +353,23 @@ bom {
]
}
}
library("Hibernate", "5.6.10.Final") {
group("org.hibernate") {
library("Hibernate", "6.1.1.Final") {
group("org.hibernate.orm") {
modules = [
"hibernate-agroal",
"hibernate-ant",
"hibernate-c3p0",
"hibernate-core-jakarta",
"hibernate-ehcache",
"hibernate-entitymanager",
"hibernate-envers-jakarta",
"hibernate-community-dialects",
"hibernate-core",
"hibernate-envers",
"hibernate-graalvm",
"hibernate-hikaricp",
"hibernate-java8",
"hibernate-jcache",
"hibernate-jpamodelgen-jakarta",
"hibernate-jpamodelgen",
"hibernate-micrometer",
"hibernate-proxool",
"hibernate-spatial",
"hibernate-testing-jakarta",
"hibernate-testing",
"hibernate-vibur"
]
}

View File

@ -45,7 +45,7 @@ dependencies {
optional("io.r2dbc:r2dbc-spi")
optional("jakarta.servlet:jakarta.servlet-api")
optional("org.apache.derby:derbytools")
optional("org.hibernate:hibernate-core-jakarta")
optional("org.hibernate.orm:hibernate-core")
optional("org.springframework:spring-jdbc")
optional("org.springframework:spring-orm")
optional("org.springframework:spring-web")

View File

@ -99,7 +99,7 @@ dependencies {
implementation("org.assertj:assertj-core")
implementation("org.cache2k:cache2k-spring")
implementation("org.apache.groovy:groovy")
implementation("org.hibernate:hibernate-jcache") {
implementation("org.hibernate.orm:hibernate-jcache") {
exclude group: "javax.activation", module: "javax.activation-api"
exclude group: "javax.persistence", module: "javax.persistence-api"
exclude group: "javax.xml.bind", module: "jaxb-api"

View File

@ -246,7 +246,7 @@ See {spring-boot-autoconfigure-module-code}/orm/jpa/HibernateJpaAutoConfiguratio
Hibernate {hibernate-docs}#caching[second-level cache] can be configured for a range of cache providers.
Rather than configuring Hibernate to lookup the cache provider again, it is better to provide the one that is available in the context whenever possible.
To do this with JCache, first make sure that `org.hibernate:hibernate-jcache` is available on the classpath.
To do this with JCache, first make sure that `org.hibernate.orm:hibernate-jcache` is available on the classpath.
Then, add a `HibernatePropertiesCustomizer` bean as shown in the following example:
include::code:MyHibernateSecondLevelCacheConfiguration[]

View File

@ -7,9 +7,7 @@ description = "Starter for using Spring Data JPA with Hibernate"
dependencies {
api(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-aop"))
api(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-jdbc"))
api("org.hibernate:hibernate-core-jakarta") {
exclude group: "jakarta.activation", module: "jakarta.activation-api"
}
api("org.hibernate.orm:hibernate-core")
api("org.springframework.data:spring-data-jpa")
api("org.springframework:spring-aspects")
}

View File

@ -23,7 +23,7 @@ dependencies {
optional("net.sourceforge.htmlunit:htmlunit") {
exclude group: "commons-logging", module: "commons-logging"
}
optional("org.hibernate:hibernate-core-jakarta")
optional("org.hibernate.orm:hibernate-core")
optional("org.junit.jupiter:junit-jupiter-api")
optional("org.seleniumhq.selenium:htmlunit-driver") {
exclude group: "commons-logging", module: "commons-logging"

View File

@ -72,7 +72,7 @@ dependencies {
}
optional("org.flywaydb:flyway-core")
optional("org.hamcrest:hamcrest-library")
optional("org.hibernate:hibernate-core-jakarta")
optional("org.hibernate.orm:hibernate-core")
optional("org.hibernate.validator:hibernate-validator")
optional("org.jooq:jooq") {
exclude(group: "javax.xml.bind", module: "jaxb-api")

View File

@ -10,12 +10,7 @@ dependencies {
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web"))
implementation("jakarta.persistence:jakarta.persistence-api")
implementation("jakarta.xml.bind:jakarta.xml.bind-api")
implementation("org.hibernate:hibernate-core-jakarta") {
exclude group: "javax.activation", module: "javax.activation-api"
exclude group: "javax.persistence", module: "javax.persistence-api"
exclude group: "javax.xml.bind", module: "jaxb-api"
exclude group: "org.jboss.spec.javax.transaction", module: "jboss-transaction-api_1.2_spec"
}
implementation("org.hibernate.orm:hibernate-core")
implementation("org.springframework:spring-orm")
runtimeOnly("com.h2database:h2")