개발을 하면서 팀원이 했던 설정이 적용이 안되어서 의아했던 설정이 있었다.
그게 바로 spring.jpa.show-sql 설정이었다.
그런데 그게 이번에 JPA 강의를 듣는 과정에서 너무 잘 적용되길래, 뭐가 이상했던건지, 추가적인 설정없이 그냥설정할 수 없는지 관련해 한번 이와 관련해서 살펴보도록 하였다.
현재 있는 프로젝트의 application.properties에서는 다음과 같이 설정하면 sql이 보이고 formatting이 된다.
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
그런데 회사껀 yml로 되어있다. 그리고 그때 위치가 이상하게 되어있었던걸로 기억한다.
spring.jpa.properties.hibernate.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
# 이런 형식으로 되어있었다.
그런데 문제는 내가 리서치를 해서 위의 원래 설정으로 바꿧는데도 적용이 안되었다는 것이다!
이런 설정으로 local에 적용을 했는데... 안나온다...
그래서 그때 했던 방법은 TransactionManager를 생성할 때 JpaProperties를 받아와 그 생성 조건을 주입해주는 것이었다.
package com.wemakeprice.v.cms.domain.configuration.jpa;
import java.util.HashMap;
public class JpaProperties extends HashMap<String, Object> {
public JpaProperties(String showSql, String formatSql, String useSqlComments) {
put("hibernate.show_sql", showSql);
put("hibernate.format_sql", formatSql);
put("hibernate.use_sql_comments", useSqlComments);
}
}
// hibernate 하위에 show_sql이라는 properties를 추가로 선언해준다.
@Bean(name = "dealEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean dealEntityManagerFactory(@Qualifier("dealEntityManagerFactoryBuilder") EntityManagerFactoryBuilder builder, @Qualifier("dealSlaveDataSource") DataSource slave, JpaProperties jpaProperties) {
return builder
.dataSource(slave)
.packages(DealRepository.class)
.persistenceUnit(Deal.NAME)
.properties(jpaProperties) // 이런식으로 jpaPoperties를 인자로 받아서 EntityManager를 만들어준다.
.build();
}
이런 현상에 의하면, 기존에 쓰는 spring.jpa.show-sql은 EntityManager가 생성될때 전달이 안된다는건데... 왜 전달이 안되는거지...?