Scalar subquery contains more than one row; SQL statement:
select room0_.room_id as col_0_0_,
room0_.title as col_1_0_,
room0_.price as col_2_0_,
(select image1_.img_url from image
image1_ where room0_.room_id=image1_.room_id)as col_3_0_
from room room0_
where room0_.category=?
limit ?
offset ? [90053-200]
@Override
public Slice<GetRoomsResponseDto> findAllByCategoryOrderByCreatedAt(String category, Pageable pageable, Long userId) {
List<GetRoomsResponseDto> returnRoom = queryFactory.select(Projections.fields(
GetRoomsResponseDto.class,
room.id,
room.title,
room.price,
// imgUrl 1개만 가져오기 room.imageList.get(0) 오류남
ExpressionUtils.as(
JPAExpressions
.select(image.imgUrl)
.from(image)
.limit(1)
.where(room.id.eq(image.room.id))
,"imgUrl"
)
)
))
.from(room)
.where(room.category.eq(category))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
return new SliceImpl<>(returnRoom, pageable, returnRoom.iterator().hasNext());
}
Scalar subquery contains more than one row; SQL statement:
오류가 났음. 구글링을 해보니 아래의 글과같이 이유를 모른다... @Override
public Slice<GetRoomsResponseDto> findAllByCategoryOrderByCreatedAt(String category, Pageable pageable, Long userId) {
List<GetRoomsResponseDto> returnRoom = queryFactory.select(Projections.fields(
GetRoomsResponseDto.class,
room.id.as("roomId"),
room.title,
room.price,
room.location,
// imgUrl 1개만 가져오기 room.imageList.get(0) 오류남
ExpressionUtils.as(
JPAExpressions
.select(image.imgUrl)
.from(image)
.where(image.id.eq(
JPAExpressions
.select(image.id.min())
.from(image)
.where(room.id.eq(image.room.id))
))
,"imgUrl"
),
// wish 여부
new CaseBuilder()
.when(wish.id.isNull())
.then((ComparableExpression<Boolean>) Expressions.asBoolean(false))
.otherwise(Expressions.asBoolean(true)).as("isWish")
))
.distinct()
.from(room)
.leftJoin(wish)
.on(room.id.eq(wish.room.id), wish.user.id.eq(userId))
.where(getCategory(category))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
return new SliceImpl<>(returnRoom, pageable, returnRoom.iterator().hasNext());
}
우아한 형제들의 Querydsl 사용법
[Querydsl] 동적 쿼리
BooleanBuilder와 BooleanExpression의 차이
Querydsl and, or 연산이 적용된 동적 쿼리 페이징 처리