작성
·
178
1
try {
Team teamA = new Team();
teamA.setName("TEAM A");
em.persist(teamA);
Team teamB = new Team();
teamB.setName("TEAM B");
em.persist(teamB);
Member member1 = new Member();
member1.setUsername("member1");
member1.setTeam(teamA);
em.persist(member1);
Member member2 = new Member();
member2.setUsername("member2");
member2.setTeam(teamA);
em.persist(member2);
Member member3 = new Member();
member3.setUsername("member3");
member3.setTeam(teamB);
em.persist(member3);
em.flush();
em.clear();
List<Member> result = em.createQuery("select m from Member AS m join m.team", Member.class)
.getResultList();
for (Member member : result) {
System.out.println("member = " + member);
System.out.println("member.getTeam().getClass() = " + member.getTeam().getClass());
}
<아래는 Console 결과입니다>
member = Member{id=3, username='member1'}
member.getTeam().getClass() = class hellojpa.Team$HibernateProxy$OSndAo5E
member = Member{id=4, username='member2'}
member.getTeam().getClass() = class hellojpa.Team$HibernateProxy$OSndAo5E
member = Member{id=5, username='member3'}
member.getTeam().getClass() = class hellojpa.Team$HibernateProxy$OSndAo5E
모두 같은 프록시 객체가 나오는 것 같습니다.
member3은 1,2와 다른 팀인데, 왜 같은 프록시 객체가 나오나요?