Java Mailing List Archive

http://www.junlu.com/

Home » user.castor »

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

Werner Guttmann

2013-06-28

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) results.next();
>       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?
How are you actually observing this behaviour ? I am really having
problems to replay such scenario.

Thanks
Werner
>
> Thanks a lot,
> JC

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


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