Language/Java
springboot 3.x + JPA + QueryDSL에서 p6spy 적용
건담아빠
2024. 9. 5. 10:07
0. gradle 버전 확인
필자는 1.9.2 버전을 사용할 것이다.
https://mvnrepository.com/artifact/com.github.gavlyukovskiy/p6spy-spring-boot-starter/1.9.2
1. 설정
1.1. build.gradle
// p6spy
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.2'
2.1. application.yml
jpa:
database: mysql
generate-ddl: false
open-in-view: false
hibernate:
ddl-auto: none # create update none 항상 조심!!
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl # 대소문자 구분
properties:
hibernate:
# show_sql: true
# format_sql: true
# use_sql_comments: true
# database-platform: com.example.querydsl.configuration.MysqlCustomDialect
3. 로그확인
대충 아래처럼 SQL에 파라미터 값이 매핑된채로 로깅된다.
select count(c1_0.ID)
from COMMUNITY c1_0
left join CATEGORY c2_0 on c2_0.CODE=c1_0.CATEGORY_CD
where c1_0.DELETE_YN=?
and c2_0.TYPE_CD=?
and c1_0.TITLE like ? escape '!'
select count(c1_0.ID)
from COMMUNITY c1_0
left join CATEGORY c2_0 on c2_0.CODE=c1_0.CATEGORY_CD
where c1_0.DELETE_YN='N'
and c2_0.TYPE_CD='CATEC00002'
and c1_0.TITLE like '%111%' escape '!';