-
카테고리
-
세부 분야
백엔드
-
해결 여부
미해결
JPA에 의해 생성된 Query의 갯수를 반환하는 방법은 없을까요?
20.09.17 16:44 작성 조회수 232
2
안녕하세요, 강의를 들으며 테스트 코드를 작성중에 있습니다.
JPA로 인해 예상치도 못하게 쿼리가 많이 생성될 수 있다는 사실을 예제를 통해 보면서, 디버깅 전략을 어떻게 해야할지 고민이 들었는데요,
혹시 JPA에서는 해당 Transaction 혹은 해당 Entity Manager에서 실제로 몇번 Database로 쿼리를 날렸는지 세어주는 메소드가 있을까요?
답변을 작성해보세요.
1
김영한
지식공유자2020.09.17
안녕하세요. 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
Kata Coder
질문자2020.09.17
스프링에서 지원해주는것은 발견했었는데 혹시 하이버네이트나 JPA에서 지원하는 것은 있을지 궁금했습니다!
https://www.logicbig.com/tutorials/spring-framework/spring-data/derived-count-query.html
강의 너무나 감사드립니다, 짧은 시간동안 집중해서 듣고 있는데 폭풍성장하는 것을 느끼고 있습니다
답변 2