From 9e8ed95db5922684559a4a743dfce5c8097a4472 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 7 Aug 2015 13:37:27 +0200 Subject: [PATCH] Avoid custom properties processing EntityManagerFactoryBuilder does not currently use the JpaProperties to initialize the `ddl-auto` and `naming-strategy` parameter automatically. We can remove that customization. In that case, we have to specify the `ddl-auto` flag explicitly as the code that auto-detects the value based on the database type is not executed anymore. --- src/main/java/demo/customer/CustomerConfig.java | 4 +--- src/main/java/demo/order/OrderConfig.java | 4 +--- src/main/resources/application.properties | 2 ++ 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/demo/customer/CustomerConfig.java b/src/main/java/demo/customer/CustomerConfig.java index e70f895..812dac9 100644 --- a/src/main/java/demo/customer/CustomerConfig.java +++ b/src/main/java/demo/customer/CustomerConfig.java @@ -7,7 +7,6 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; import org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryBuilder; -import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -33,12 +32,11 @@ public DataSource customerDataSource() { @Bean public LocalContainerEntityManagerFactoryBean customerEntityManager( - EntityManagerFactoryBuilder builder, JpaProperties jpaProperties) { + EntityManagerFactoryBuilder builder) { return builder .dataSource(customerDataSource()) .packages(Customer.class) .persistenceUnit("customers") - .properties(jpaProperties.getHibernateProperties(customerDataSource())) .build(); } diff --git a/src/main/java/demo/order/OrderConfig.java b/src/main/java/demo/order/OrderConfig.java index c5446b8..2a5747d 100644 --- a/src/main/java/demo/order/OrderConfig.java +++ b/src/main/java/demo/order/OrderConfig.java @@ -7,7 +7,6 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; import org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryBuilder; -import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -30,12 +29,11 @@ public DataSource orderDataSource() { @Bean public LocalContainerEntityManagerFactoryBean orderEntityManager( - EntityManagerFactoryBuilder builder, JpaProperties jpaProperties) { + EntityManagerFactoryBuilder builder) { return builder .dataSource(orderDataSource()) .packages(Order.class) .persistenceUnit("orders") - .properties(jpaProperties.getHibernateProperties(orderDataSource())) .build(); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 95c2686..d11dcd3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,3 +1,5 @@ +spring.jpa.properties.hibernate.hbm2ddl.auto=create + app.customer.datasource.url=jdbc:h2:mem:customers;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE app.customer.datasource.driver-class-name=org.h2.Driver