kotlin-jdsl icon indicating copy to clipboard operation
kotlin-jdsl copied to clipboard

연관관계가 없는 Entity 간에 left join을 할 수 있는 방법이 있나요?

Open eastperson opened this issue 2 years ago • 5 comments

안녕하세요, 제공해주신 라이브러리를 유용하게 사용하고 있는 개발자입니다 :)

현재 QueryDSL을 대신하여 JDSL로 쿼리를 구성하고 있는데, '연관관계가 없는 엔티티 간에 on 절을 이용하여 left join'을 해야하는 경우가 있습니다. 이렇게 조인해서 얻은 필드값은 DTO로 맵핑해서 반환하려고 합니다.

하지만 JDSL에서 제공하는 on절은 Cross Join만 가능하게 정의되어있는 것 같습니다.

https://github.com/line/kotlin-jdsl#cross-join

override fun <T> join(entity: EntitySpec<T>, predicate: PredicateSpec) {
    lazyJoins().add(CrossJoinSpec(entity))
    lazyWheres().add(predicate)
}

혹시 연관관계가 없는 두 엔티티를 left join 하는 방법이 있을까요?

eastperson avatar Jul 21 '22 06:07 eastperson

cross join example If you look at this code, non-associative joins are possible through the on clause of join , even if there is no direct association with each other.

-- korean cross join example 을 보시면 서로 연관관계를 직접 맺지 않아도 join 의 on 절을 통해 비 연관관계 조인이 가능합니다.

cj848 avatar Jul 24 '22 22:07 cj848

이거 저도 고민하는 문제인데? 아직 close하면 안 되지 않나요. 연관관계 없는 엔티티끼리 join할 때, left outer join이 안 돼요. 아직 지원을 안 하는 건가요?

stella6767 avatar Sep 28 '22 08:09 stella6767

이거 저도 고민하는 문제인데? 아직 close하면 안 되지 않나요. 연관관계 없는 엔티티끼리 join할 때, left outer join이 안 돼요. 아직 지원을 안 하는 건가요?

stella6767 avatar Sep 28 '22 08:09 stella6767

@stella6767 맞습니다. 연관 관계가 없는 Entity 간의 left join은 지원하지 않습니다. 이는 Criteria API의 한계이며 추후 kotlin-jdsl 3.0으로 이관되면서 JPQL 기반으로 변경되면 해소될 예정입니다.

하지만 kotlin-jdsl 3.0을 위핸 개발 리소스가 없어 내년을 기약하고 있습니다. 😢

========================================================

You are right, kotlin-jdsl does not support left join between unrelated Entities. This is a limitation of the Criteria API and will be resolved in kotlin-jdsl 3.0 which is use JPQL.

However, we have no development resources for kotlin-jdsl 3.0, so we are expecting next year.

shouwn avatar Sep 28 '22 09:09 shouwn

I misunderstood. sorry. @shouwn Thank you.

cj848 avatar Sep 29 '22 23:09 cj848

@eastperson 안녕하세요. Kotlin JDSL 3.0.0-SNAPSHOT이 배포되었습니다.

3.0.0에서는 이제 연관관계가 없는 Entity간의 left join이 가능합니다. 혹시 아직까지 Kotlin JDSL을 사용하고 계시다면 한번 snapshot을 통해서 원하시는 쿼리가 작성되는지 테스트해봐주세요.

오랫동안 기다리게 하여 죄송하고, 기대해주셔서 감사합니다.

아래 docs를 참고하시면 Kotlin JDSL 3.0.0을 사용하시는 데 도움이 될 것으로 생각됩니다. https://kotlin-jdsl.gitbook.io/docs/

이 이슈는 3.0.0으로도 연관관계가 없는 Entity 간 left join이 안 될 경우 재오픈하겠습니다.

========================

Kotlin JDSL 3.0.0-SNAPSHOT has been released in snapshot repository.

With 3.0.0, left join between unrelated entities is now possible. If you are still using Kotlin JDSL, please test the snapshot to see if it builds the query you want.

We apologize for the long wait and thank you for your patience.

shouwn avatar Sep 04 '23 23:09 shouwn