querydsl empty result 에러 해결.

정명진·2023년 6월 16일
0
post-custom-banner

출연자 없으면 에러 나던것 해결.

해당 원인은 performer의 artist를 이용해서 생긴 문제였다.
이렇게 하면서 artist와 크로스 조인도 발생하고 값이 없어 empty가 반환되었다. 하지만 left join 시 null이 나오면 안된다. 퍼포먼스가 없는한...이를 artistEntity와 performer.artist와 leftjoin 하고 셀렉트시 artistEntity 를 사용했더니 출연자가 없어도 익셉션이 나지 않고 데이터를 잘 가져왔다.

수정 전 코드

Map<Long, PerformanceDetailQueryDslDtoV2> result = queryFactory
                .from(performanceEntity)
                .leftJoin(performanceImageEntity).on(performanceEntity.eq(performanceImageEntity.performance))
                .leftJoin(priceGradeEntity).on(performanceEntity.eq(priceGradeEntity.performance))
                .leftJoin(performerEntity).on(performanceEntity.eq(performerEntity.performance))
                .where(performanceEntity.id.eq(id))
                .transform(groupBy(performanceEntity.id).as(new QPerformanceDetailQueryDslDtoV2(
                        performanceEntity.id,
                        performanceEntity.title,
                        performanceEntity.place,
                        performanceEntity.musicalDateTime,
                        performanceEntity.purchaseLimit,
                        performanceEntity.limitAge,
                        performanceEntity.startDate,
                        performanceEntity.endDate,
                        performanceEntity.ticketOpenDate,
                        performanceEntity.ticketEndDate,
                        set(performanceImageEntity.imageUrl),
                        set(new QPriceInfoDto(priceGradeEntity.gradeName, priceGradeEntity.price)),
                        set(new QCommonArtistDto(performerEntity.artist.id, performerEntity.artist.name, performerEntity.artist.profileImageUrl)
                        ))));

이를 다음과 같이 변경해서 해결했다.

Map<Long, PerformanceDetailQueryDslDtoV2> result = queryFactory
                .from(performanceEntity)
                .leftJoin(performanceImageEntity).on(performanceEntity.eq(performanceImageEntity.performance))
                .leftJoin(priceGradeEntity).on(performanceEntity.eq(priceGradeEntity.performance))
                .leftJoin(performerEntity).on(performanceEntity.eq(performerEntity.performance))
                .leftJoin(artistEntity).on(performerEntity.artist.eq(artistEntity))
                .fetchJoin()
                .where(performanceEntity.id.eq(id))
                .transform(groupBy(performanceEntity.id).as(new QPerformanceDetailQueryDslDtoV2(
                        performanceEntity.id,
                        performanceEntity.title,
                        performanceEntity.place,
                        performanceEntity.musicalDateTime,
                        performanceEntity.purchaseLimit,
                        performanceEntity.limitAge,
                        performanceEntity.startDate,
                        performanceEntity.endDate,
                        performanceEntity.ticketOpenDate,
                        performanceEntity.ticketEndDate,
                        set(performanceImageEntity.imageUrl),
                        set(new QPriceInfoDto(priceGradeEntity.gradeName, priceGradeEntity.price)),
                        set(new QCommonArtistDto(artistEntity.id, artistEntity.name, artistEntity.profileImageUrl)))));

이걸로 하루 순삭..!

profile
개발자로 입사했지만 정체성을 잃어가는중... 다시 준비 시작이다..
post-custom-banner

0개의 댓글