From 51fedd6528f10727c85d8dee9d3481750e892d4c Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 19 Jul 2021 13:52:40 +0100 Subject: [PATCH] Reinstate support for Hibernate < 5.5 See gh-27352 --- .../autoconfigure/orm/jpa/HibernateProperties.java | 10 +++++----- .../src/main/resources/application.properties | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hibernate52/src/main/resources/application.properties 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 da3b926c9ee..994e33d3590 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 @@ -173,18 +173,18 @@ public class HibernateProperties { private void applyNamingStrategies(Map properties) { applyNamingStrategy(properties, AvailableSettings.IMPLICIT_NAMING_STRATEGY, this.implicitStrategy, - SpringImplicitNamingStrategy.class.getName()); + () -> SpringImplicitNamingStrategy.class.getName()); applyNamingStrategy(properties, AvailableSettings.PHYSICAL_NAMING_STRATEGY, this.physicalStrategy, - CamelCaseToUnderscoresNamingStrategy.class.getName()); + () -> CamelCaseToUnderscoresNamingStrategy.class.getName()); } private void applyNamingStrategy(Map properties, String key, Object strategy, - Object defaultStrategy) { + Supplier defaultStrategy) { if (strategy != null) { properties.put(key, strategy); } - else if (defaultStrategy != null && !properties.containsKey(key)) { - properties.put(key, defaultStrategy); + else { + properties.computeIfAbsent(key, (k) -> defaultStrategy.get()); } } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hibernate52/src/main/resources/application.properties b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hibernate52/src/main/resources/application.properties new file mode 100644 index 00000000000..ff76f097438 --- /dev/null +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-hibernate52/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl \ No newline at end of file