EBJQL does not support subqueries in the from
clause (you can use them in select
and where
), so this exact query cannot be performed. You could try rewriting the query, in your case the following should be equivalent:
select count(distinct e.myField) from myEntity e group by e.myField having ...
Alternatively, just use createNativeQuery()
and use your original query without rewriting it in HQL. This of course breaks portability.
HINT: if you're using Eclipse, get the Hibernate plugin from http://www.jboss.org/tools or the marketplace. It allows you to write and execute queries directly from the IDE (see query prototyping in the Hibernate tools documentation). Other IDEs could have similar capabilities also.