JPQL:为什么'按组'不能正常工作 [英] JPQL: why 'group by' does not work properly
问题描述
使用hibernate 4.2.5执行JPQL:
从Chargeback中选择c作为cc通过c将cc.customer作为c组加入order by max(cc.created)
Usecase:向客户展示最新的chargbacks。
生成org.hibernate.exception.SQLGrammarException:无法提取ResultSet
- 当使用
从Chargeback中选择c.id作为cc将cc.customer作为c group by c by order by max(cc.created)
它将起作用。 - 使用
从Chargeback中选择c作为cc通过c.id加入cc.customer作为c组,c ......所有列顺序由max(cc.created) code>
这是一个错误吗?为什么JPQL不包括*? (从这个用例是非常必要的)
不需要 - 原生sql当然可以解决它。我们假设JPQL已经成熟。
有一个功能请求: 然而,请记住,按所有列分组可能会有所不同不是性能最好的选择。 Executing JPQL using hibernate 4.2.5: Usecase: show customers with the latest chargbacks. produces org.hibernate.exception.SQLGrammarException: could not extract ResultSet Is it a bug? why JPQL does not include *? (from this usecase it is very necessary) NO need - native sql of course to solve it. We assume JPQL is mature. There is a feature request for this: HHH-1615. However, keep in mind that grouping by all columns may not be the best option performance-wise. 这篇关于JPQL:为什么'按组'不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
select c from Chargeback as cc join cc.customer as c group by c order by max(cc.created)
select c.id from Chargeback as cc join cc.customer as c group by c order by max(cc.created)
it will work.select c from Chargeback as cc join cc.customer as c group by c.id, c......all columns order by max(cc.created)