inflearn logo
강의

Khóa học

Chia sẻ kiến thức

Thực hành! Dữ liệu Spring JPA

Mô hình miền mẫu và xác nhận hoạt động

team 조회시 query 관련

274

dysh10172845

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

0

영한님 log와 달리,

제가 조회를 했을때는 hibernate가 for문에서 해당 팀을 조회 하는 순서에 따라 select쿼리를 날려서

데이터를 db에서 가져온 후 print해주는데요

영한님 로그에서는 미리 team1,2 를 다 조회하고 그 다음에 출력해주는것으로 보입니다.

(여기서 이미 조회해서 영속성 컨텐츠로 만든 것들은 다시 select 쿼리를 날리진 알고요

team 1, 2 의 경우 1번씩만 날림) em.clear해서 캐시를 초기화 했기 때문에,

getTeam을 하였을 때,
아래의 결과 처럼 getTeam으로 조회 하려고 할때, hibernate가 select 쿼리를 날리는게 맞다고 보는데


영한님 로그에서는 어떻게 hibernate가 미리 2개를 다 조회할 것을 알고 select문을 먼저 2번 날린 것인지 궁금합니다.

System.out.println("============");
for(Member member:members){
System.out.println(member);
System.out.println(member.getTeam());
}
System.out.println("============");
============
Member(id=3, username=member1, age=10)
2021-07-30 05:38:40.449 DEBUG 1508 --- [           main] org.hibernate.SQL                        : select team0_.team_id as team_id1_1_0_, team0_.name as name2_1_0_ from team team0_ where team0_.team_id=?
2021-07-30 05:38:40.451  INFO 1508 --- [           main] p6spy                                    : #1627591120451 | took 0ms | statement | connection 3| url jdbc:h2:tcp://localhost/~/lecture_datajpa
select team0_.team_id as team_id1_1_0_, team0_.name as name2_1_0_ from team team0_ where team0_.team_id=?
select team0_.team_id as team_id1_1_0_, team0_.name as name2_1_0_ from team team0_ where team0_.team_id=1;
Team(id=1, name=teamA)
Member(id=4, username=member2, age=10)
Team(id=1, name=teamA)
Member(id=5, username=member3, age=10)
2021-07-30 05:38:40.460 DEBUG 1508 --- [           main] org.hibernate.SQL                        : select team0_.team_id as team_id1_1_0_, team0_.name as name2_1_0_ from team team0_ where team0_.team_id=?
2021-07-30 05:38:40.461  INFO 1508 --- [           main] p6spy                                    : #1627591120461 | took 0ms | statement | connection 3| url jdbc:h2:tcp://localhost/~/lecture_datajpa
select team0_.team_id as team_id1_1_0_, team0_.name as name2_1_0_ from team team0_ where team0_.team_id=?
select team0_.team_id as team_id1_1_0_, team0_.name as name2_1_0_ from team team0_ where team0_.team_id=2;
Team(id=2, name=teamB)
Member(id=6, username=member4, age=10)
Team(id=2, name=teamB)
============

spring-boot java JPA spring

Câu trả lời 3

0

yh

안녕하세요. 승현님

해당 궁금증은 JPA 기본편에서 자세히 알려드립니다.

감사합니다.

0

dysh10172845

그렇다면 추가적으로 궁금한 것은,

실무에서 어떤 상황에서는 eager로 받아야 하는  case도 있을 것같은데,

어떨때 eager처리하는 지 궁금합니다.

0

dysh10172845

아 제가 미리 fetct lazy 옵션을 줘서 그런거였네요 확인했습니다.

existsByUserIdAndProjectId vs existsByUserAndProject 중 어떤 방식이 적절할까요?

0

66

1

existsByUserIdAndProjectId vs existsByUserAndProject 중 어떤 방식이 적절할까요?

0

103

3

MemberRepository 구현체

0

56

1

pdf 표현 질문드립니다.

0

60

1

로그가 남지 않는 문제.

0

79

1

테스트 라이브러리가 강의는 junit4가 맞나요??

0

68

2

pdf 파일과 차이점이 있는 것같은데 문제 없나요?

0

69

2

@PrePersist, @PreUpdate 호출 시점 질문드립니다.

0

91

2

Sort 인터페이스는 잘 사용 안하나요?

0

51

1

스캔대상 질문드립니다.

0

45

1

하이버네이트6에서의 최적화에 이은 질문

0

82

1

save() vs saveAndFlush DB 통신 횟수

0

51

1

순수 JPA 리포지토리 코드 수정부분

0

85

2

bulk연산 후 flush하는 이유를 모르겠어요

0

149

3

bulk insert 질문입니다.

0

174

2

교만했던 것 같아요.

0

145

1

RESTful 강의는 안하시는 건지 궁금합니다.

0

144

2

동적 테이블에 대한 질문

0

84

1

영속성 전이와 연관관계

0

130

2

강의 10:25 질문

0

72

1

단건 update 질문

0

94

2

엔티티 와 도메인의 경계

0

126

1

UsernameOnlyDto 타입 type mismatch 오류

0

118

1

Projection 개념과 데이터 전달과정에 대해 질문 있습니다.

0

135

1