반응형
728x90
반응형
1) 연관관계 적용
Member member = new Member();
member.setUsername("kimseohae");
member.setAge(10);
Team team = new Team();
team.setName("team1");
team.setName("team");
member.setTeam(team);
em.persist(team);
em.persist(member);
em.flush();
em.clear();
2) Join 예제
- Inner
TypedQuery<Member> query = em.createQuery("select m from Member as m inner join m.team t", Member.class);
List<Member> resultList = query.getResultList();
System.out.println("result.size = " + resultList.size());
(수행쿼리)
/* select
m
from
Member as m
inner join
m.team t */ 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_
inner join
TEAM team1_
on member0_.TEAM_ID=team1_.id
- Left
TypedQuery<Member> query = em.createQuery("select m from Member as m left join m.team t", Member.class);
List<Member> resultList = query.getResultList();
System.out.println("result.size = " + resultList.size());
(수행쿼리)
/* select
m
from
Member as m
left join
m.team t */ 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
- Seta
TypedQuery<Member> query = em.createQuery("select m from Member m, Team t where m.username = t.name", Member.class);
List<Member> resultList = query.getResultList();
System.out.println("result.size = " + resultList.size());
(수행쿼리)
/* select
m
from
Member m,
Team t
where
m.username = t.name */ 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_ cross
join
TEAM team1_
where
member0_.username=team1_.name
반응형
'Coding > JPA' 카테고리의 다른 글
[JPA 프로그래밍] 1. JPA 란 무엇인가? (0) | 2022.06.17 |
---|---|
[JPA] JQPL enum Type 조건문 사용하는 경우 (0) | 2022.03.08 |
[JPA] JQPL 사용해서 페이징 수행 (0) | 2022.02.24 |
[JPA] 복합키 - 비식별관계 매핑하기 (@IdClass, @EmbeddedId) (0) | 2022.02.09 |
[JPA] 고급매핑 - 조인 전략, 단일 테이블 전략, 구현 클래스별 테이블 전략 (0) | 2022.02.07 |