JPQL: why 'group by' does not work properly

ε祈祈猫儿з 提交于 2020-01-07 03:45:07

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/35058953/jpql-why-group-by-does-not-work-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!