Wednesday, 28 August 2013

Extra lazy fetching through two collections

Extra lazy fetching through two collections

I have an Object A which has a collection of B objects (many B objects to
one A object), which, at the same time, have a collection of C items (many
C objects to one B object).
I want to be able to list objects of A class with a count number of C
objects that are (traversing both collections) associated to A.
So in this case:
A ---- B1------C1
------C2
B2------C3
B3------C4
------C5
A would have a C object count of 5.
I know extra lazy fetching allows to get the number of objects in a
collection without actually bringing the whole collection (internally
using a SELECT count()), but since I have to traverse through two
collections, what would be the optimal way to do this?
Keep in mind that I'm fetching a collection of A objects, so I would
prefer not having to go through all A elements manually querying for the
count.

No comments:

Post a Comment