Nathan Q
Nathan Q

Reputation: 1902

where clause on property of objects in a collection

Simplified:

Class1 {
    private Collection<Class2> items;
}

Class2 {
    private String name;
}

Now I want to be able to retrieve all Class1 objects that have a Class2 object in items where name is like for example 'abc';

I think I have to use the elements() function in HQL, but not sure yet how to use the property values.

Any pointers are welcome!

Upvotes: 1

Views: 1531

Answers (1)

JB Nizet
JB Nizet

Reputation: 691645

No, you just need to make a join:

select c1 from Class1 c1 inner join c1.items c2 where c2.name  = 'abc'

Read the Hibernate documentation on HQL, associations and joins.

Upvotes: 3

Related Questions