JPA JPQL 조인(JOIN)

KMS·2022년 4월 12일
0

JPA Basics

목록 보기
15/20
post-thumbnail

			//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

profile
Student at Sejong University Department of Software

0개의 댓글