Hi all,
I'm tearing my hair out here.
I have a table of Issues, each of which has a Severity. I need to create a query counting the number of Issues per Severity (easy enough) with rows of 0 for Severities with no Issues (this is killing me). The latest problem is that named parameters do not seem to work in subqueries, and I need to trim the counts according to other criteria (such as i.status.id in (:status_List)).
Code:
select i.severity.id, count(i) from Issue i right outer join i.severity where i.status.id in (:status_List) group by i.severity.id;
The above doesn't return what I need, as the where clause filters everything, not just the Issues.
I've tried:
Code:
select s.id, (select count(i) from Issue i where i.severity.id = s.id and i.status.id in (:status_List)) from Severity s group by s.id;
The above gets me "Named parameter does not appear in Query".
I've tried joining to a subquery:
Code:
select s.id, count(i) from Severity s left outer join (from Issue i where i.severity.id = s.id and i.status.id in (:status_List)) group by s.id;
The above doesn't work because joining to a subquery is apparently not supported.
At this point my alternatives appear to be two:
1) munge the results after the fact to add in missing Severities (ugly, innit, but it would work)
2) drop to a SqlQuery, which is a whole world of hurt due to above mentioned other criteria, which can get quite complicated and are best described in HQL, not SQL... that's why I'm using Hibernate in the first place, eh? :-)
Any suggestions? Help would be greatly appreciated at this point.
Regards,
-scott