작성
·
221
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)
============