From b10c57551cb4ab3d2f48baacc0eb90a92fd3b114 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Sat, 9 Jul 2022 14:43:25 +0200 Subject: [PATCH] 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 Closes gh-31674 --- .../build.gradle | 2 +- .../spring-boot-autoconfigure/build.gradle | 6 ++--- .../orm/jpa/HibernateProperties.java | 25 ------------------- ...itional-spring-configuration-metadata.json | 9 +++++++ .../orm/jpa/HibernatePropertiesTests.java | 13 ---------- .../db/changelog/db.changelog-city.yaml | 3 ++- .../src/test/resources/db/city/V1__init.sql | 2 +- .../spring-boot-dependencies/build.gradle | 19 +++++++------- .../spring-boot-devtools/build.gradle | 2 +- .../spring-boot-docs/build.gradle | 2 +- .../src/docs/asciidoc/howto/data-access.adoc | 2 +- .../spring-boot-starter-data-jpa/build.gradle | 4 +-- .../build.gradle | 2 +- spring-boot-project/spring-boot/build.gradle | 2 +- .../spring-boot-smoke-test-jpa/build.gradle | 7 +----- 15 files changed, 32 insertions(+), 68 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle b/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle index e3fc608c87..47da1fd424 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle @@ -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") { diff --git a/spring-boot-project/spring-boot-autoconfigure/build.gradle b/spring-boot-project/spring-boot-autoconfigure/build.gradle index c95c909f12..656d4c4de6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/build.gradle +++ b/spring-boot-project/spring-boot-autoconfigure/build.gradle @@ -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") { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateProperties.java index aa46da1258..93e32b6c6e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateProperties.java @@ -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 getAdditionalProperties(Map existing, HibernateSettings settings) { Map 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 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 result) { if (!result.containsKey(AvailableSettings.SCANNER) && ClassUtils.isPresent(DISABLED_SCANNER_CLASS, null)) { result.put(AvailableSettings.SCANNER, DISABLED_SCANNER_CLASS); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 94d3cbb53a..31a2af4169 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -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", diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernatePropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernatePropertiesTests.java index 426807df55..9114188f18 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernatePropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernatePropertiesTests.java @@ -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) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-city.yaml b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-city.yaml index 4e7328a39e..c46dc1dacb 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-city.yaml +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-city.yaml @@ -4,7 +4,8 @@ databaseChangeLog: author: dsyer changes: - createSequence: - sequenceName: hibernate_sequence + sequenceName: city_seq + incrementBy: 50 - createTable: tableName: city columns: diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/city/V1__init.sql b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/city/V1__init.sql index 88cc1f4919..571f6fa46e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/city/V1__init.sql +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/city/V1__init.sql @@ -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, diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index e6b802f6e9..52abfc9118 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -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" ] } diff --git a/spring-boot-project/spring-boot-devtools/build.gradle b/spring-boot-project/spring-boot-devtools/build.gradle index f64dd18b22..a0c6858f67 100644 --- a/spring-boot-project/spring-boot-devtools/build.gradle +++ b/spring-boot-project/spring-boot-devtools/build.gradle @@ -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") diff --git a/spring-boot-project/spring-boot-docs/build.gradle b/spring-boot-project/spring-boot-docs/build.gradle index ea344591b3..0ac842189f 100644 --- a/spring-boot-project/spring-boot-docs/build.gradle +++ b/spring-boot-project/spring-boot-docs/build.gradle @@ -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" diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/data-access.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/data-access.adoc index d31f095ecb..0cf12e95fe 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/data-access.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/data-access.adoc @@ -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[] diff --git a/spring-boot-project/spring-boot-starters/spring-boot-starter-data-jpa/build.gradle b/spring-boot-project/spring-boot-starters/spring-boot-starter-data-jpa/build.gradle index 7659d5f8e2..c7829df20b 100644 --- a/spring-boot-project/spring-boot-starters/spring-boot-starter-data-jpa/build.gradle +++ b/spring-boot-project/spring-boot-starters/spring-boot-starter-data-jpa/build.gradle @@ -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") } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/build.gradle b/spring-boot-project/spring-boot-test-autoconfigure/build.gradle index 382fb6dec7..d398fef2c0 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/build.gradle +++ b/spring-boot-project/spring-boot-test-autoconfigure/build.gradle @@ -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" diff --git a/spring-boot-project/spring-boot/build.gradle b/spring-boot-project/spring-boot/build.gradle index ff0de07354..ac331560fe 100644 --- a/spring-boot-project/spring-boot/build.gradle +++ b/spring-boot-project/spring-boot/build.gradle @@ -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") diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/build.gradle index 5594b7e850..1edf900da3 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/build.gradle @@ -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")