본문 바로가기
Java

QueryDSL 조인 예제

by jayden-lee 2019. 6. 5.
728x90

Inner Join

QCustomer customer = QCustomer.customer;
QCompany company = QCompany.company;
queryFactory.select(customer.firstName, customer.lastName, company.name)
    .from(customer)
    .innerJoin(customer.company, company)
    .fetch();

Left Join

queryFactory.select(customer.firstName, customer.lastName, company.name)
    .from(customer)
    .leftJoin(customer.company, company)
    .fetch();

다음과 같이 SQL처럼 on을 사용해서 조인 조건을 변경할 수 있다.

queryFactory.select(customer.firstName, customer.lastName, company.name)
    .from(customer)
    .leftJoin(company).on(customer.company.eq(company))
    .fetch();

참고자료

댓글