From a1dd6e32930cdd1031e8f9acc65fbd940164d2a1 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Fri, 17 May 2013 16:07:40 +0100 Subject: [PATCH] Fix data sample (needed an enum for spring.jpa.ddl_auto) --- .../src/main/resources/application.properties | 1 + .../orm/jpa/HibernateJpaAutoConfiguration.java | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 spring-bootstrap-samples/spring-bootstrap-data-sample/src/main/resources/application.properties diff --git a/spring-bootstrap-samples/spring-bootstrap-data-sample/src/main/resources/application.properties b/spring-bootstrap-samples/spring-bootstrap-data-sample/src/main/resources/application.properties new file mode 100644 index 0000000000..04e13807d5 --- /dev/null +++ b/spring-bootstrap-samples/spring-bootstrap-data-sample/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.jpa.ddl_auto: create_drop \ No newline at end of file diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java index 67b9d45d2d..31ee1a97f0 100644 --- a/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java @@ -45,6 +45,14 @@ import org.springframework.util.StringUtils; @Import(JpaComponentScanDetector.class) public class HibernateJpaAutoConfiguration extends JpaAutoConfiguration { + public static enum DDLAUTO { + none, validate, update, create, create_drop; + @Override + public String toString() { + return this.name().toLowerCase().replace("_", "-"); + } + } + private static final Map EMBEDDED_DATABASE_DIALECTS; static { EMBEDDED_DATABASE_DIALECTS = new LinkedHashMap(); @@ -61,15 +69,14 @@ public class HibernateJpaAutoConfiguration extends JpaAutoConfiguration { @Value("${spring.jpa.showSql:${spring.jpa.show_sql:false}}") private boolean showSql; - @Value("${spring.jpa.generateDdl:${spring.jpa.generate_ddl:false}}") - private boolean generateDdl; + @Value("${spring.jpa.ddlAuto:${spring.jpa.ddl_auto:none}}") + private DDLAUTO ddlAuto; @Bean @Override public JpaVendorAdapter jpaVendorAdapter() { HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter(); adapter.setShowSql(this.showSql); - adapter.setGenerateDdl(this.generateDdl); if (StringUtils.hasText(this.databasePlatform)) { adapter.setDatabasePlatform(this.databasePlatform); } @@ -84,6 +91,10 @@ public class HibernateJpaAutoConfiguration extends JpaAutoConfiguration { // FIXME: detect EhCache properties.put("hibernate.cache.provider_class", "org.hibernate.cache.HashtableCacheProvider"); + if (this.ddlAuto != DDLAUTO.none) { + properties.put("hibernate.hbm2ddl.auto", this.ddlAuto.toString()); + } + } }