JPA에 의해 생성된 Query의 갯수를 반환하는 방법은 없을까요?
427
작성한 질문수 1
안녕하세요, 강의를 들으며 테스트 코드를 작성중에 있습니다.
JPA로 인해 예상치도 못하게 쿼리가 많이 생성될 수 있다는 사실을 예제를 통해 보면서, 디버깅 전략을 어떻게 해야할지 고민이 들었는데요,
혹시 JPA에서는 해당 Transaction 혹은 해당 Entity Manager에서 실제로 몇번 Database로 쿼리를 날렸는지 세어주는 메소드가 있을까요?
답변 2
1
안녕하세요. Kata Coder님
https://www.logicbig.com/tutorials/spring-framework/spring-data/derived-count-query.html는 DB에 저장된 데이터 수를 세는 쿼리를 만들어주는 기능입니다^^
원하시는 기능은 다음 옵션을 사용하시면 됩니다^^
hibernate.generate_statistics=true
성능에 영향을 미치니 로컬이나, 개발서버에서만 사용하시는게 좋습니다^^
2020-09-17 16:55:41.800 INFO 2852 --- [nio-8080-exec-4] i.StatisticalLoggingSessionEventListener : Session Metrics {
694979 nanoseconds spent acquiring 1 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
1691669 nanoseconds spent preparing 7 JDBC statements;
2225822 nanoseconds spent executing 7 JDBC statements;
0 nanoseconds spent executing 0 JDBC batches;
0 nanoseconds spent performing 0 L2C puts;
0 nanoseconds spent performing 0 L2C hits;
0 nanoseconds spent performing 0 L2C misses;
0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections);
14179 nanoseconds spent executing 1 partial-flushes (flushing a total of 0 entities and 0 collections)
}
2020-09-17 16:51:34.082 INFO 2828 --- [nio-8080-exec-4] i.StatisticalLoggingSessionEventListener : Session Metrics {
596899 nanoseconds spent acquiring 1 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
2083482 nanoseconds spent preparing 4 JDBC statements;
1680342 nanoseconds spent executing 4 JDBC statements;
0 nanoseconds spent executing 0 JDBC batches;
0 nanoseconds spent performing 0 L2C puts;
0 nanoseconds spent performing 0 L2C hits;
0 nanoseconds spent performing 0 L2C misses;
0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections);
2520 nanoseconds spent executing 1 partial-flushes (flushing a total of 0 entities and 0 collections)
}
0
스프링에서 지원해주는것은 발견했었는데 혹시 하이버네이트나 JPA에서 지원하는 것은 있을지 궁금했습니다!
https://www.logicbig.com/tutorials/spring-framework/spring-data/derived-count-query.html
강의 너무나 감사드립니다, 짧은 시간동안 집중해서 듣고 있는데 폭풍성장하는 것을 느끼고 있습니다
실무 조언 관련 질문입니다.
0
40
1
H2데이터베이스 파일 생성
0
48
2
서브쿼리 강의에서 ALL 예시 관련 질문드립니다.
0
49
2
수정또는 삭제시 영속성 엔티티에 값이 무조건 있어야 하나요?
0
46
1
JPQL 메소드와 락
0
49
1
Delivery @OneToOne
0
55
1
17강 4~5분대 테이블 값 조회가 안됩니다.
0
85
2
UnsupportedOperationException 발생
0
80
3
H2 Database 연결이 안됩니다.
0
87
2
연관관계 매핑 질문드립니다.
0
79
2
h2데이터베이스 실행오류
0
103
2
persistence.xml
0
101
2
양방향 연관관계에서 연관관계의 주인(mappedBy)을 왜 꼭 정해야 하나요?
0
76
1
영속성 컨텍스트
0
61
1
JPA 프록시
0
87
1
Native Query와 MyBatis
0
62
1
영속성 컨텍스트는 어떤 메모리에 저장되는건가요?
0
81
1
임베디드 타입 예시 코드 관련 질문
0
110
3
명시적 조인에서 별칭을 주면 왜 객체에 접근할 수 있나요
0
89
3
인텔리제이 패키지 커서 단축키 질문
0
104
2
혹시 현재는 ID 데이터 타입이 String이면 안되나요?
0
134
1
양방향 연관관계 시 연관관계 주인을 설정하는 이유
0
67
1
임베디드 타입과 MappedSuperClass의 차이점이 궁금합니다.
0
95
1
데이터베이스가 초기화되는 것 같아요
1
173
2





