Re: Lazy Fetches

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Jul 03 2003 - 12:20:09 EDT

  • Next message: Michael Amster: "Modeler question for one-to-one logical mapping"

    > It appears that in Cayenne everything is a lazy fetch, as in, data
    > accessed through relations isn't fetched until the user tries to use it.
    > Is there any way to force the fetching of data via these relationships,
    > non-lazy style?

    Yes, it is called "prefetching". It hasn't been documented till now
    (though nightly builds already contain a new chapter in the user guide).

    In a nutshell use 'SelectQuery.addPrefetch("relationshipName")'

    > Also, if I fetch an object from the DB that potentially a huge amount of
    > related objects, does it keep populating them until I run out of memory
    > or is there some sort of safeguard to prevent this? Say I have a SITE
    > table with a one-to-many relation to USERS and users have tables
    > branching off of them. I fetch a site object and then perform an
    > operation on each user it's related to. Would I have to be concerned of
    > hitting too many users and running out of memory because it's fetched
    > all this information for each user I hit on? (Say millions?)

    If there is a need to process millions of objects, there is a good chance
    of running out of memory. Instead of fetching them all into memory, you
    should look into ResultIterator:

      http://objectstyle.org/cayenne/userguide/perform/index.html

    Andrus



    This archive was generated by hypermail 2.0.0 : Thu Jul 03 2003 - 12:20:10 EDT