From edaf2d89e4cd60423c8dcb9e0577ed28b33753e2 Mon Sep 17 00:00:00 2001 From: Lim Jonguk Date: Sun, 13 Feb 2022 01:14:37 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=86=8C=EC=8A=A4=EC=A0=95?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/config/database/DataSourceConfig.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/xit/core/config/database/DataSourceConfig.java b/src/main/java/com/xit/core/config/database/DataSourceConfig.java index 319b596..0de0069 100644 --- a/src/main/java/com/xit/core/config/database/DataSourceConfig.java +++ b/src/main/java/com/xit/core/config/database/DataSourceConfig.java @@ -34,6 +34,7 @@ import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.EnableTransactionManagement; +import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; import java.sql.Date; import java.sql.Time; @@ -56,6 +57,8 @@ import java.util.Map; sqlSessionFactoryRef = "sqlSessionFactory" ) public class DataSourceConfig { + @Value("${spring.jpa.properties.hibernate.hbm2ddl.auto}") + String hbm2ddlAuto; // JPA //static final String[] REPO_PACKAGES = new String[]{"com.xit.biz.**.repository", "com.xit.core.**.repository"}; static final String[] ENTITY_PACKAGES = new String[]{"com.xit.biz.**.entity", "com.xit.core.**.entity"}; @@ -88,14 +91,14 @@ public class DataSourceConfig { } @Bean - public LocalContainerEntityManagerFactoryBean entityManagerFactory(@Value("${spring.jpa.properties.hibernate.hbm2ddl.auto}") String hbm2ddlAuto) { + public EntityManagerFactory entityManagerFactory() { HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); vendorAdapter.setDatabasePlatform(jpaProperties().getDatabasePlatform()); vendorAdapter.setDatabase(jpaProperties().getDatabase()); vendorAdapter.setShowSql(jpaProperties().isShowSql()); HibernateProperties hibernateProperties = new HibernateProperties(); - hibernateProperties.setDdlAuto(hbm2ddlAuto); + hibernateProperties.setDdlAuto(this.hbm2ddlAuto); Map propMap = hibernateProperties.determineHibernateProperties( jpaProperties().getProperties() , new HibernateSettings()); @@ -106,15 +109,17 @@ public class DataSourceConfig { emf.setPersistenceUnitName("default"); emf.setJpaVendorAdapter(vendorAdapter); emf.setJpaPropertyMap(propMap); //jpaProperties().getProperties()); + emf.afterPropertiesSet(); //emf.getJpaPropertyMap().put(AvailableSettings.BEAN_CONTAINER, new SpringBeanContainer(entityManagerFactory)) - return emf; + + return emf.getObject(); } @Primary @Bean - public PlatformTransactionManager jpaTransactionManager(LocalContainerEntityManagerFactoryBean entityManagerFactory) { + public PlatformTransactionManager jpaTransactionManager() { JpaTransactionManager transactionManager = new JpaTransactionManager(); - transactionManager.setEntityManagerFactory(entityManagerFactory.getObject()); + transactionManager.setEntityManagerFactory(entityManagerFactory()); transactionManager.setNestedTransactionAllowed(true); return transactionManager; } @@ -166,7 +171,7 @@ public class DataSourceConfig { conf.setMapUnderscoreToCamelCase(true); conf.setLocalCacheScope(LocalCacheScope.SESSION); // SESSION / STATEMENT conf.setJdbcTypeForNull(JdbcType.OTHER); // NULL / VARCHAR / OTHER 파라메터에 null 값이 있는경우 처리 - conf.setLazyLoadTriggerMethods(new HashSet(Arrays.asList("equals", "clone", "hashCode", "toString"))); + conf.setLazyLoadTriggerMethods(new HashSet<>(Arrays.asList("equals", "clone", "hashCode", "toString"))); conf.setCallSettersOnNulls(true); // 조회시 null값 필드 set conf.setAggressiveLazyLoading(true); conf.setReturnInstanceForEmptyRow(true);