I have a Parent object which has many children. Using HQL I can do a simple query to find parents which have children of a specified age like so:
"select parent from Parent as parent join Children as child where child.age=10"
I think I just learned today that if a parent has two children age 10 (twins) then I get the same parent twice. Which in SQL terms makes sense because I joined to the children collection so I end up with two result rows, one for each child. In HQL I can get the result I want by adding 'distinct' to the query.
"select distinct parent from Parent as parent join Children as child where child.age=10"
Gives me all the parents that have a child of that age, but each parent only once, just what I want. I can get the first result, the same parent repeated for each child, using the Criteria api but I can't figure out how to get the distinct list. Can I?
|