hibernate criteria group 查询错误
hibernate criteria group Query is wrong
我正在尝试使用 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")
。因此生成的查询将在其 select 子句中包含 orderNumber
。
我认为没有必要明确指定 Projections.property("orderNumber")
。能否请您删除它并尝试。
同样适用于使用 groupProperty(..)
指定的任何其他字段。
我正在尝试使用 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")
。因此生成的查询将在其 select 子句中包含 orderNumber
。
我认为没有必要明确指定 Projections.property("orderNumber")
。能否请您删除它并尝试。
同样适用于使用 groupProperty(..)
指定的任何其他字段。