Use null instead of 'none' for ddlAuto

Fixes gh-1012
pull/1031/head
Dave Syer 11 years ago
parent 56e70ca585
commit 251dbddc6e

@ -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

Loading…
Cancel
Save