I have a "Parent" and a "Child" classes in a simple one-to-many relationship. I want to fetch all Parents that contain at least one Child with a given property (e.g. "name"). In SQL, it would be something like this:
Code:
select p.*
from parent p
where exists
(select c.childId from child c
where c.parentId = p.parentId and c.name=:name)
.
I also want a fetch join (i.e. I want to force the eager population of the Children collection in a Parent with *all* its children).
How do I do it in HQL? I tried something like this:
Code:
from Parent p inner join fetch p.children c
where c.name=:name
But it does not populate *all* children in the Parent, only those that
match the :name parameter.
I need to get the full collection.
Any help would be greatly appreciated!