본문 바로가기
Spring

[Spring] JPA Querydsl Unsupported expression

by clolee 2022. 10. 9.

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

 

 

 

댓글