问题描述
我想使用Criteria查询基于平均客户评价获取产品列表。我使用条件查询聚合函数AVG编写了一段代码,并保留了GROUP BY子句。但是以某种方式,我遇到了“不是表达式分组” 异常。我试图在Google中搜索以解决,但没有任何帮助。在下面发布代码
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Object[]> cq = builder.createQuery(Object[].class);
Root<GdbCustomerProductReviewImpl> productReview = cq.from(GdbCustomerProductReviewImpl.class);
Path productPath = productReview.get("product");
Path documentPath = productPath.get("photo");
Path categoryPath = productPath.get("defaultCategory");
Path productCategoryPath = categoryPath.get("prdCategory");
cq.multiselect(productReview.get("id"),productPath.get("url"),productPath.get("skuName"),documentPath.get("id"));
cq.where(builder.isNotNull(productPath.get("id")));
cq.where(builder.equal(productReview.get("status"),"ACTIVE"));
cq.where(builder.equal(productReview.get("reviewType"),"PRODUCT"));
cq.where(builder.equal(productPath.get("isEnable"),Boolean.TRUE));
cq.where(builder.equal(productPath.get("status"),StatusType.APPROVED.getType()));
cq.where(builder.isNotNull(productPath.get("defSkuMap")));
cq.where(builder.equal(productCategoryPath.get("isEnabled"),Boolean.TRUE));
cq.groupBy(productReview.get("id"));
Expression event_count = builder.avg(productReview.get("rating"));
cq.orderBy(builder.desc(event_count));
List<Object[]> resultList = em.createQuery(cq).setMaxResults(size).getResultList();
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)