springframework/Spring Data JPA

JPA 생성 쿼리 파라미터 로깅, Spring Data JPA 사용시 명심해야 할 것들

Jungsoomin :) 2020. 11. 14. 00:59

하이버네이트의 쿼리는 반드시 계속 보고 파라미터를 체크하자.

  • 그래야만 쿼리를 튜닝하고 하이버네이트에 대해서 깊이 이해할 수 있다.
  • 하이버네이트가 원하는 만큼의 데이터를 가져오는지.
  • 하이버네이트가 원하는 쿼리를 발생시키는지.

하이버네이트가 발생시키는 쿼리의 파라미터를 체크하자.

  • logging.level.org.hibernate.descriptor.sql=trace
#최소한의 데이터 소스 설정
spring.datasource.url=jdbc:postgresql://localhost:5432/datajpa
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.username=postgres
spring.datasource.password=postgres

spring.jpa.open-in-view=true

# 자동 쿼리 생성 , validate 는 검증. create 는 언제나 드랍하고 새로만듬. create-drop 실행 시 생성 종료시 드랍. update 변경 시에만 변경 점 적용
spring.jpa.hibernate.ddl-auto=update
spring.jpa.generate-ddl=true

# show sql
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

# SQL 문 파라미터 값 살펴보기
logging.level.org.hibernate.type.descriptor.sql=trace

'springframework > Spring Data JPA' 카테고리의 다른 글

Spring Data Common : Repository  (0) 2020.11.15
Spring Data JPA 활용 개요.  (0) 2020.11.15
Spring Data JPA 의 원리와 소개  (0) 2020.11.14
Query  (0) 2020.11.13
Fetch 전략  (0) 2020.11.13