执行此JPQL:
select o.key, count(o.id), sum(o.errors) from MyEntity o
group by o.key
Hibernate提交以下SQL:
select
myentityn0_.key as col_0_0_,
count(myentityn0_.id) as col_1_0_,
sum(myentityn0_.errors) as col_2_0_
from
MYENTITY myentityn0_
group by
myentityn0_.key
但是如何在不使用Hibernate创建的列名的情况下使用“order by”?如果我在JPQL中使用as
,则SQL不会更改。
答案 0 :(得分:4)
在order by
:
select
o.key,
count(o.id),
sum(o.errors)
from MyEntity o
group by o.key
order by sum(o.errors)