작성
·
209
0
@Test
public void join_on_filtering(){
List<Tuple> result = queryFactory
.select(member, team)
.from(member)
.leftJoin(member.team, team)
.on(team.name.eq("teamA"))
.orderBy(member.username.asc())
.fetch();
for (Tuple tuple : result) {
System.out.println("tuple = " + tuple);
}
Tuple member1 = result.get(0);
Tuple member2 = result.get(1);
assertThat(member1.get(team.name)).isEqualTo("teamA");
@Test
public void join_on_filtering(){
List<Tuple> result = queryFactory
.select(member, team)
.from(member)
.leftJoin(member.team, team)
.on(team.name.eq("teamA"))
.orderBy(member.username.asc())
.fetch();
for (Tuple tuple : result) {
System.out.println("tuple = " + tuple);
}
Tuple member1 = result.get(0);
Tuple member2 = result.get(1);
assertThat(member1.get(team).getName()).isEqualTo("teamA");
assertThat(member2.get(member).getUsername()).isEqualTo("member2");
@Test
public void group(){
List<Tuple> result = queryFactory
.select(team.name, member.age.avg())
.from(member)
.join(member.team, team)
.groupBy(team.name)
.fetch();
Tuple teamA = result.get(0);
Tuple teamB = result.get(1);
assertThat(teamA.get(team.name)).isEqualTo("teamA");
assertThat(teamA.get(member.age.avg())).isEqualTo(15);
}
답변 1
1
안녕하세요. 우와아앙님
다음 부분을 보시면 답을 찾을 수 있습니다.
.select(member, team)
이렇게 하면 프로젝션 대상이 member, team입니다. 따라서 튜블에 들어가는 데이터도 member, team 객체가 들어가게 됩니다.
따라서 데이터를 조회할 때는 다음과 같이 조회하시면 됩니다.
member1.get(team).getName()
감사합니다.