Hey all,
I found a strange problem with a rather complex group by query when it comes to counting the number of rows that will be returned for the query - the created HQL query contains a having clause (which is correct), but omits the group by clause (which is not correct and leads to an exception, stating that having was encountered without group by). I debugged the problem and found this code in JPQLSerializer.serialize():
// group by
if (!groupBy.isEmpty() && !forCountRow) {
append(GROUP_BY).handle(COMMA, groupBy);
}
// having
if (having != null) {
append(HAVING).handle(having);
}
If there is any reason why group by in count queries should not work then this code is wrong, because if the group by is omitted, clearly the having clause must also be omitted. On the other hand, if omitting the groupBy clause when forCountRow is true is wrong, then this is also a bug. Can someone please clarify why group by is omitted in count cases?
Thanks in advance
Sven