//SELECT m.*, t.name FROM member m LEFT JOIN team t ON m.team_id = t.id WHERE t.name="TeamA";
String query = "select m from Member m left join m.team t where t.name=:teamName";
List<Member> resultList = em.createQuery(query, Member.class)
.setParameter("teamName", "TeamA")
.getResultList();
for (Member member : resultList) {
System.out.println("member.getAge() = " + member.getAge() + ", member.getTeam() = " + member.getTeam().getName()
+ ", member.getTeam().getId() = " + member.getTeam().getId());
}
결과:
member.getAge() = 22, member.getTeam() = TeamA, member.getTeam().getId() = 1
member.getAge() = 24, member.getTeam() = TeamA, member.getTeam().getId() = 1
member.getAge() = 26, member.getTeam() = TeamA, member.getTeam().getId() = 1
member.getAge() = 28, member.getTeam() = TeamA, member.getTeam().getId() = 1
member.getAge() = 30, member.getTeam() = TeamA, member.getTeam().getId() = 1