- 내부조인
- 외부조인
- 세타조인
- ON절 활용한 조인: 조인 대상을 미리 필터링(JPA 2.1부터 지원)
- 연관관계 없는 엔티티 외부조인(하이버네이트 5.1부터 지원)
Team team = new Team();
team.setName("teamA");
em.persist(team);
Member member = new Member();
member.setUsername("member1");
member.setAge(10);
member.setTeam(team);
em.persist(member);
em.flush();
em.clear();
String query1 = "select m from Member m join m.team t"; //내부조인
String query2 = "select m from Member m left join m.team t"; //외부조인
String query3 = "select m from Member m, Team t where m.username = t.name"; //세타조인
String query4 = "select m from Member m left join m.team t on t.name = 'teamA'"; //on절
String query5 = "select m from Member m left join Team t on m.username = t.name"; //연관관계 없는 경우
List<Member> resultList = em.createQuery(query5, Member.class)
.getResultList();
tx.commit();
select
member0_.Id as id1_0_,
member0_.age as age2_0_,
member0_.TEAM_ID as team_id4_0_,
member0_.username as username3_0_
from
Member member0_
left outer join
Team team1_
on member0_.TEAM_ID=team1_.Id
and (
team1_.name='teamA'
)
- 실행 쿼리(연관관계 없는 경우): PK키 비교X
select
member0_.Id as id1_0_,
member0_.age as age2_0_,
member0_.TEAM_ID as team_id4_0_,
member0_.username as username3_0_
from
Member member0_
left outer join
Team team1_
on (
member0_.username=team1_.name
)