I have Cat and Kitten entities, that are in many-to-one relationship (Cat has many kittens) I need to return those Cats and only those Kittens of that Cat that matches certain conditions.
I.e.
from Cat cat left join fetch cat.kittens kitten where kitten.color = 'gray'
Using this hql i ran into the following problem: If one Cat has N 'gray' kittens, I got N instances of the same Cat returned with N kittens pre-loaded in Cat.kittens collection.
If I will use 'left join' w/o 'fetch' I got correct number of Cats, but Cat.kittens now contains all kittens, including 'gray'.
You can't use pagination with an outer join fetch. If you start thinking about the SQL and how the resultset looks like, it should be quite obvious why it doesn't work.
Co-Author of <a href="http://www.manning.com/bauer" target="_blank" rel="nofollow">Hibernate in Action</a>
Looks like I will need to refactor query to not fetch 'one-to-many' assosiations in one select. However, is there any other ways to make Hibernate lazy loading of assosiated objects using some criteria restrictions ? I found session.filter(collection, "hql") not suitable since it returns the subset of elemnts in list rather then list as property of selected object.