Querydsl Unsupported expression 오류 해결 방법
.as()를 통해 alias 사용하기
qHolding.goods_cnt.sum().as("sumGoodsCnt"),
Expressions.stringTemplate("group_concat({0})", qHolding.user.user_id).as("userIds")
GoodsHoldingDto.java
public class GoodsHoldingDto {
private Long goodsId;
private String goodsNm;
private Integer sumGoodsCnt;
private String userIds;
@QueryProjection
public GoodsHoldingDto(Long goodsId, String goodsNm, Integer sumGoodsCnt, String userIds) {
this.goodsId = goodsId;
this.goodsNm = goodsNm;
this.sumGoodsCnt = sumGoodsCnt;
this.userIds = userIds;
}
}
전체 코드
/**
* 상품 별 판매 개수, 보유자 리스트
*/
public List<GoodsHoldingDto> findListHolding() {
QHolding qHolding = QHolding.holding;
List<GoodsHoldingDto> list = jpaQueryFactory
.select(Projections.fields(
GoodsHoldingDto.class,
product.goods_id.as("goodsId"),
product.goods_nm.as("goodsNm"),
qHolding.goods_cnt.sum().as("sumGoodsCnt"),
Expressions.stringTemplate("group_concat({0})", qHolding.user.user_id).as("userIds")
))
.from(qHolding)
.join(qHolding.product, product)
.join(qHolding.user, user)
.groupBy(qHolding.product.goods_id)
.fetch();
return list;
}
참고 :
https://stackoverflow.com/questions/32312622/querydsl-unsupported-expression-sum
'Spring' 카테고리의 다른 글
[Spring/Error] Not a managed type: class 명 error (0) | 2023.01.25 |
---|---|
[Spring] JPA Querydsl 사용하기 (group_concat 함수) (1) | 2022.10.19 |
[Spring + React] react input 데이터 springboot Controller 로 전달하기 (0) | 2022.09.05 |
[Spring] SpringBoot + AWS RDS + React 연동하기 (0) | 2022.09.02 |
[Spring + React] 스프링과 리액트 연동하기 (0) | 2022.08.31 |
댓글