问题
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
- 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. - 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