diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitialization.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitialization.java index 3d7bd07314..d61eb5242b 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitialization.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitialization.java @@ -160,6 +160,7 @@ public class DataSourceInitialization implements return resources; } + @SuppressWarnings("serial") public static class DataSourceInitializedEvent extends ApplicationEvent { public DataSourceInitializedEvent(DataSource source) { 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 7cc9e51000..085923b648 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 @@ -27,6 +27,7 @@ import org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.orm.jpa.SpringNamingStrategy; import org.springframework.orm.jpa.vendor.Database; +import org.springframework.util.StringUtils; /** * External configuration properties for a JPA EntityManagerFactory created by Spring. @@ -181,8 +182,12 @@ public class JpaProperties { private Map getDeferredAdditionalProperties( Map properties, DataSource dataSource) { Map deferred = getAdditionalProperties(properties); - deferred.put("hibernate.hbm2ddl.auto", - getDeferredDdlAuto(properties, dataSource)); + String ddlAuto = getDeferredDdlAuto(properties, dataSource); + if (StringUtils.hasText(ddlAuto) && !"none".equals(ddlAuto)) { + deferred.put("hibernate.hbm2ddl.auto", ddlAuto); + } else { + deferred.remove("hibernate.hbm2ddl.auto"); + } return deferred; } @@ -197,7 +202,7 @@ public class JpaProperties { DEFAULT_NAMING_STRATEGY.getName()); } if (this.deferDdl) { - result.put("hibernate.hbm2ddl.auto", "none"); + result.remove("hibernate.hbm2ddl.auto"); } else { result.put("hibernate.hbm2ddl.auto", this.ddlAuto); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/CustomHibernateJpaAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/CustomHibernateJpaAutoConfigurationTests.java index b6d4edabb9..9adb8d8a2a 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/CustomHibernateJpaAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/CustomHibernateJpaAutoConfigurationTests.java @@ -16,6 +16,11 @@ package org.springframework.boot.autoconfigure.orm.jpa; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + import javax.sql.DataSource; import org.junit.After; @@ -29,9 +34,6 @@ import org.springframework.boot.test.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Configuration; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; - /** * Tests for {@link HibernateJpaAutoConfiguration}. * @@ -64,7 +66,7 @@ public class CustomHibernateJpaAutoConfigurationTests { String actual = bean.getHibernateProperties(dataSource).get( "hibernate.hbm2ddl.auto"); // Default is generic and safe - assertThat(actual, equalTo("none")); + assertThat(actual, is(nullValue())); } @Test