I have a one-to-many relationship. I would like to construct this query:
Give me all the parents that have only one child and for this child child.Type=X
Since I 'm learning, please show me the query with the Criteria API and with HQL. Thanks.
And btw, is there any automatic way to know what HQL is identical to a criteria expression ?
Update:
It seems I found how to do it in HQL:
@"select Parent
from Parent parent
join parent.Children ch
where (ch.Type = :chType) and
(select count(*) from parent.Children) = 1")
But is it well done? How is the performance? I have the intuition that the count(*) is not well placed...