From aaa5b9ddf16ebcbd2c454261e701e89fa8769d31 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 22 May 2014 20:33:24 +0100 Subject: [PATCH] Continue to support spring.jpa.hibernate.namingstrategy In 1.0, the property spring.jpa.hibernate.namingstrategy could be used to configure Hibernate's naming strategy. This was at odds with most other configuration where binding to namingStrategy would require a property with some indication that it was two separate words, for example: naming-strategy, naming_strategy, or namingStrategy This commit adds a new setter, setNamingstrategy, to JpaProperties so that an app that was using namingstrategy in 1.0 continues to work in 1.1. Issue #928 --- .../autoconfigure/orm/jpa/JpaProperties.java | 11 ++++++++--- .../HibernateJpaAutoConfigurationTests.java | 18 +++++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java index 57efa9f3ee..dc14d65d97 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java @@ -28,8 +28,9 @@ import org.springframework.orm.jpa.vendor.Database; /** * External configuration properties for a JPA EntityManagerFactory created by Spring. - * + * * @author Dave Syer + * @author Andy Wilkinson * @since 1.1.0 */ @ConfigurationProperties(prefix = "spring.jpa") @@ -99,7 +100,7 @@ public class JpaProperties { * Get configuration properties for the initialization of the main Hibernate * EntityManagerFactory. The result will always have ddl-auto=none, so that the schema * generation or validation can be deferred to a later stage. - * + * * @param dataSource the DataSource in case it is needed to determine the properties * @return some Hibernate properties for configuration */ @@ -109,7 +110,7 @@ public class JpaProperties { /** * Get the full configuration properties for the Hibernate EntityManagerFactory. - * + * * @param dataSource the DataSource in case it is needed to determine the properties * @return some Hibernate properties for configuration */ @@ -136,6 +137,10 @@ public class JpaProperties { this.namingStrategy = namingStrategy; } + public void setNamingstrategy(Class namingStrategy) { + this.setNamingStrategy(namingStrategy); + } + public String getDdlAuto() { return this.ddlAuto; } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java index cd05fce0da..41f4c12477 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java @@ -26,9 +26,10 @@ import static org.junit.Assert.assertThat; /** * Tests for {@link HibernateJpaAutoConfiguration}. - * + * * @author Dave Syer * @author Phillip Webb + * @author Andy Wilkinson */ public class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigurationTests { @@ -51,6 +52,21 @@ public class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigura assertThat(actual, equalTo("org.hibernate.cfg.EJB3NamingStrategy")); } + @Test + public void testNamingStrategyThatWorkedInOneDotOhContinuesToWork() { + EnvironmentTestUtils.addEnvironment(this.context, + "spring.jpa.hibernate.namingstrategy:" + + "org.hibernate.cfg.EJB3NamingStrategy"); + setupTestConfiguration(); + + this.context.refresh(); + LocalContainerEntityManagerFactoryBean bean = this.context + .getBean(LocalContainerEntityManagerFactoryBean.class); + String actual = (String) bean.getJpaPropertyMap().get( + "hibernate.ejb.naming_strategy"); + assertThat(actual, equalTo("org.hibernate.cfg.EJB3NamingStrategy")); + } + @Test public void testCustomNamingStrategyViaJpaProperties() throws Exception { EnvironmentTestUtils.addEnvironment(this.context,