JPQL:为什么'按组'不能正常工作 [英] JPQL: why 'group by' does not work properly

查看:161
本文介绍了JPQL:为什么'按组'不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用hibernate 4.2.5执行JPQL:

 从Chargeback中选择c作为cc通过c将cc.customer作为c组加入order by max(cc.created)

Usecase:向客户展示最新的chargbacks。



生成org.hibernate.exception.SQLGrammarException:无法提取ResultSet


  1. 当使用
    从Chargeback中选择c.id作为cc将cc.customer作为c group by c by order by max(cc.created)它将起作用。

  2. 使用从Chargeback中选择c作为cc通过c.id加入cc.customer作为c组,c ......所有列顺序由max(cc.created) code>

这是一个错误吗?为什么JPQL不包括*? (从这个用例是非常必要的)

不需要 - 原生sql当然可以解决它。我们假设JPQL已经成熟。

解决方案

有一个功能请求:

然而,请记住,按所有列分组可能会有所不同不是性能最好的选择。


Executing JPQL using hibernate 4.2.5:

select c from Chargeback as cc join cc.customer as c group by c order by max(cc.created)

Usecase: show customers with the latest chargbacks.

produces org.hibernate.exception.SQLGrammarException: could not extract ResultSet

  1. When using select c.id from Chargeback as cc join cc.customer as c group by c order by max(cc.created) it will work.
  2. When using select c from Chargeback as cc join cc.customer as c group by c.id, c......all columns order by max(cc.created)

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆