I have an entity model with a parent child relationship. I'd like to be able to retrieve a number of attributes for the parent, and also a number of counts for different criteria of the children. What's the best way to go about this?
Is there any way this can be done with HQL, or am I better off just using createSQLQuery()? Or even just to do it at the entity level (with attributes/methods on my parent entity to "GetCountOfChildrenWhere(Criteria criteria)"
I would like to be able to do something like the following SQL
Code:
SELECT p.id,
p.name,
SUM(CASE c.Status WHEN 'Open' THEN 1 ELSE 0 END) AS Open,
SUM(CASE c.Status WHEN 'Closed' THEN 1 ELSE 0 END) AS Closed
from parent, child
where parent.id = child.parentid