Well, you are right. This is the solution for my example above. But unfortunately, as I have written in my last post, I need a general solution that works too if there are more than one grouping attributes:
Code:
select NAME, CITY, sum(AGE) from PERSON where NAME like :nameParam and CITY like :cityParam group by NAME, CITY
(String name;
String city;
int age;)
Your statement does not work here because count() allows only one parameter.
My question remains:
Is there any way to count the number of rows that would be returned by this query without actually executing it? (That is to use the count() function somehow or any other way).
This all would be no problem if Hibernate would support subqueries in the from clause - a really missing feature in my opinion.
I hope that my example is complete now. In my real query, there are more than one aggregate functions in the select clause, but I really hope that this makes no difference. To tell the whole story: I use such a query in an application that uses paging (implemented using the Hibernate paging functionalities, which work fine). In addition to displaying one page of results, I have to display the total number of hits. But I did not find any way to do this without executing the complete (none-paged) query. By the way: We use Oracle 9i which implements the paging quite good.