gpt4 book ai didi

java - hibernate criteria group 查询错误

转载 作者:行者123 更新时间:2023-11-30 08:39:18 26 4
gpt4 key购买 nike

我正在尝试使用 Criteria 生成以下查询:

select order_number, order_date, sum(order_amount)
from st_pur_orders
group by ORDER_NUMBER,ORDER_DATE;

这是我的标准:

  Criteria cr = session.createCriteria(StPurOrders.class);
cr.setProjection(Projections.projectionList()
.add(Projections.property("orderNumber"), "orderDate")
.add(Projections.sum("orderAmount"))
.add(Projections.groupProperty("orderNumber"))
.add(Projections.groupProperty("orderDate")));
cr.setResultTransformer(Transformers.aliasToBean(PurOrderColl.class));
list = cr.list();

但是在后台生成的查询是这样的:

select this_.ORDER_NUMBER as y0_, sum(this_.ORDER_AMOUNT) as y1_,
this_.ORDER_NUMBER as y2_, this_.ORDER_DATE as y3_
from STOCK.ST_PUR_ORDERS this_
group by this_.ORDER_NUMBER, this_.ORDER_DATE;

我的问题是为什么 ORDER_NUMBER 字段被列出两次?

最佳答案

My Question is why is the ORDER_NUMBER field being listed twice?

您的条件已经有 Projections.groupProperty("orderNumber")。因此生成的查询将在其选择子句中包含 orderNumber

我认为不需要明确指定 Projections.property("orderNumber")。能否请您删除它并尝试。

同样适用于使用 groupProperty(..) 指定的任何其他字段。

关于java - hibernate criteria group 查询错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36214412/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com