Commit 251dbddc authored by Dave Syer's avatar Dave Syer

Use null instead of 'none' for ddlAuto

Fixes gh-1012
parent 56e70ca5
......@@ -160,6 +160,7 @@ public class DataSourceInitialization implements
return resources;
}
@SuppressWarnings("serial")
public static class DataSourceInitializedEvent extends ApplicationEvent {
public DataSourceInitializedEvent(DataSource source) {
......
......@@ -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<String, String> getDeferredAdditionalProperties(
Map<String, String> properties, DataSource dataSource) {
Map<String, String> 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);
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment