Hi together,
i would like to fetch only parts of the a collection using a hibernate criteria query. As an example lets say i have a Class object containing multiple Student objects. Now i would like to get a list of classes but only the german students should be fetched into the students collection (the rest is not needed and would be massive overhead) with just one database query.
In later versions of hibernate (i think before 3.6.4) this could be done by using a filtered createCriteria like this:
Code:
criteria.createCriteria("students", "studentscollection", Criteria.LEFT_JOIN, Restrictions.eq("studentscollection.country", "DE"));
The problem is that in current versions of hibernate this leaves the collection uninitialized and triggers massive database queries to load the whole collections for every single collection on access. This is a massive performance problem causing hundreds of queries instead of one.
Is there any solution in current hibernate versions to get this done using one query?
Thanks a lot!
Yours
Thomas