Fix data sample (needed an enum for spring.jpa.ddl_auto)

This commit is contained in:
Dave Syer 2013-05-17 16:07:40 +01:00
parent 369b0834a0
commit a1dd6e3293
2 changed files with 15 additions and 3 deletions

View File

@ -0,0 +1 @@
spring.jpa.ddl_auto: create_drop

View File

@ -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<EmbeddedDatabaseType, String> EMBEDDED_DATABASE_DIALECTS;
static {
EMBEDDED_DATABASE_DIALECTS = new LinkedHashMap<EmbeddedDatabaseType, String>();
@ -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());
}
}
}