Gabor Beres wrote:
Hi!
I have Parent object, which has a collection of Child objects. Child has an attribute attr1.
I need those Parent objects, which has a Child that has an attr specified by a parameter.
My try:
String query = "from Parent r where r in (select a.parent from Child a where a.attr1=:attr1)";
The problem is that this query can return the same Parent object several times. I need a solution where there is a distinct on Parent, so if there are duplicates, i only get one of those.
I tried "select distinct r from parent r....." but it not works.
Secound, i need the query to be as fast as possible, so if there is a solution that is faster than the above, please give me the details.
Thanks.
How about:
Code:
select distinct p from Parent p inner join p.children child where child.attr=:attr
Farzad-