[odb-users] Looking for the most efficent way to load a object hiearchy

Boris Kolpackov boris at codesynthesis.com
Wed Nov 18 10:08:15 EST 2015

Hi Sverre,

Sverre Eplov <sverre at awion.dk> writes:

> A - B + C1 
>       + C2
>       + C3 + D1
>            + D2
> I would now like to load a number of A’s (say, about 200) with full object
> graph as well. How can this be done most efficiently?

When it comes to to-many relationships, it is hard to achieve absolute
optimum performance without a significant amount of manual work.
Specifically, joining everything together (i.e., the object loading view
way) will not necessarily result in better performance since you will be
loading multiple copies of C, B, and A objects.

So the recommended way is to start with essentially what Andrew suggested:
let ODB load everything in the default way. BUT (and this can make a huge
difference to the performance), make sure that all your objects have
session support enabled and you have an active session (object cache). This
means that if you have the same B/C/D objects pointed-to from multiple
places, they will only be loaded from the database once.

Only if/when this results in unacceptable performance, should you think
about optimizing it. And the way to do it is essentially load everything
(using object loading views) backwards, starting from all the D's, then
C's, then B's, and finally A's.


More information about the odb-users mailing list