• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

Querydsl 일대다 관계에서 빈객체 반환에 대한 질문이있습니다.

24.01.31 10:56 작성 조회수 119

0

 

List<ContentsDtoRes> contents = queryFactory
        .selectFrom(ParentEntity)
        .leftJoin(ParentEntity.childList, childEntity)
        .leftJoin(childEntity.childChildEntity, childchildEntity)
        .where(
                systemDelYnEq(condition.getDelYn()),
                autoDelYnEq(condition.getDelYn())
        )
        .offset(pageable.getOffset())
        .limit(pageable.getPageSize())
        .transform(
                groupBy(systemEntity.sysId).list(
                        new QContentsDtoRes(
                                parentEntity.a,
                                parentEntity.b,
                                parentEntity.c,
                                parentEntity.d,
                                parentEntity.e,
                                list(
                                        new QChildDto(
                                                childEntity.a,
                                                childEntity.b
                                        )
                                ),
                                list(
                                        new QchildChildDto(
                                                childChild.a,
                                                childChild.b,
                                                childChild.c,
                                                childChild.d
                                        )
                                )
                        )
                )
        );

안녕하세요 강사님. ㅎ
Querydsl 의 일대다 관계에 대해서 질문이있어 올리게되었습니다.
예를들어 위와 같이 부모엔티티와 자식엔티티의 일대 다 관계가 될 경우
ParentEntity 는 존재하고 childEntity 가 없을 경우 querydsl 에서는 NPE 가 아닌
빈객체를 반환하게 되는데 아래와 같이 @QueryProject 생성자
하위에서 이렇게 빈객체를 체크하고 비워주는 작업을 할 수 밖에 없는건가요.?


    this.childList.addAll(childList.stream()
            .filter(child -> child.getId() != null).collect(Collectors.toList()));

    this.childChildList.addAll(childChildList.stream()
            .filter(childchild -> childchild.getId() != null).collect(Collectors.toList()));
}

혹시 다른 방법이 있다면 어떤 방법이 있을지 궁금합니다.
항상 좋은강의 감사합니다.! 좋은하루되세요

답변 1

답변을 작성해보세요.

0

안녕하세요. 시스아웃님

이 부분은 저도 정확히 잘 모르겠습니다.

관련해서 아시는 분 있으면 답변 부탁드려요.

감사합니다.