inflearn logo
강의

Khóa học

Chia sẻ kiến thức

Lập trình JPA tiêu chuẩn Java ORM - Cơ bản

Tải tức thì và tải trì hoãn

JPA에 의해 생성된 Query의 갯수를 반환하는 방법은 없을까요?

465

Kata Coder

1 câu hỏi đã được viết

2

안녕하세요, 강의를 들으며 테스트 코드를 작성중에 있습니다.

JPA로 인해 예상치도 못하게 쿼리가 많이 생성될 수 있다는 사실을 예제를 통해 보면서, 디버깅 전략을 어떻게 해야할지 고민이 들었는데요, 

혹시 JPA에서는 해당 Transaction 혹은 해당 Entity Manager에서 실제로 몇번 Database로 쿼리를 날렸는지 세어주는 메소드가 있을까요?

JPA java

Câu trả lời 2

1

yh

안녕하세요. 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

스프링에서 지원해주는것은 발견했었는데 혹시 하이버네이트나 JPA에서 지원하는 것은 있을지 궁금했습니다! 

https://www.logicbig.com/tutorials/spring-framework/spring-data/derived-count-query.html

강의 너무나 감사드립니다, 짧은 시간동안 집중해서 듣고 있는데 폭풍성장하는 것을 느끼고 있습니다

안녕하세요 늦은 나이 늦깎이 개발자 지망생입니다.

0

50

1

질문있습니다.

0

72

1

리뉴얼 시기

0

145

2

변경감지(더티체킹) 이후 플러시할 경우의 쿼리

0

109

1

단일 테이블 시 null 값과 연관관계 필요성 질문

0

102

1

벌크연산에서 member.getAge 호출 시 영속성 컨텍스트에서 데이터를 가져오는건가요?

0

130

2

inheritance startegy 선택시 고려사항

0

97

1

Entity 동등성 비교

0

84

1

실무 조언 관련 질문입니다.

0

118

1

H2데이터베이스 파일 생성

0

133

2

서브쿼리 강의에서 ALL 예시 관련 질문드립니다.

1

130

2

수정또는 삭제시 영속성 엔티티에 값이 무조건 있어야 하나요?

0

111

1

JPQL 메소드와 락

0

115

1

Delivery @OneToOne

0

118

1

17강 4~5분대 테이블 값 조회가 안됩니다.

0

200

2

UnsupportedOperationException 발생

0

210

3

H2 Database 연결이 안됩니다.

0

159

2

연관관계 매핑 질문드립니다.

0

155

2

h2데이터베이스 실행오류

0

181

2

persistence.xml

0

212

2

양방향 연관관계에서 연관관계의 주인(mappedBy)을 왜 꼭 정해야 하나요?

0

152

1

영속성 컨텍스트

0

126

1

JPA 프록시

0

162

1

Native Query와 MyBatis

0

149

1