Java Mailing List Archive

Home » user.castor »

Re: [castor-user] lazy mappings always load their data

Werner Guttmann


Replies: Find Java Web Hosting

Author LoginPost Reply
Hi Justin,

On 23.05.2013 20:56, Justin Case wrote:
> Hello group,
> I really don't get the idea of "lazy loading". From the Castor site I
> read the following:
> "Per definition, when an instance of Department is loaded through e.g.
> Database.load(), Castor will not (pre-)load the Employee instance
> referenced (as such reducing the size pf the initial query as well as
> the size of the result set returned). Only when the Emplyoee instance is
> accessed through Department.getEmployee(), Castor will load the actual
> object into memory from the persistence store.
> This means that if the Employee instance is not accessed at all, not
> only will the initial query to load the Department object have had its
> complexity reduced, but no performance penalty will be incurred for the
> additional access to the persistence store either."
> As a consequence, I would have expected that a lazy object if never
> accessed, will never be loaded into memory. This seems to not be the
> case. A code like the following:
>       Database db = _jdo.getDatabase();
>       db.begin();
>       OQLQuery query = db.getOQLQuery("SELECT product FROM " +
> Product.class.getName() + " product WHERE id = $1");
>       query.bind(new Integer(1));
>       QueryResults results = query.execute(AccessMode.ReadOnly);
>       Product product = (Product);
>       db.commit();
>       db.close();
> will load all the lazy mappings from the Product class (1:1 or whatever)
> during the commit() phase.
> Am I getting something wrong, or is it by design so?
No, I think that you understood things right. In your code sample you
are not loading any Employees via the Product member getEmplyoees, so
there should not be any commit checks.

If there are, it needs some investigation(s).

Kind Regards
> Thanks a lot,
> JC

To unsubscribe from this list, please visit:

©2008 - Jax Systems, LLC, U.S.A.