ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kuntz, Tim" <tim_ku...@pamperedchef.com>
Subject RE: iBatis Book - Lazy Loading Description
Date Fri, 05 Jan 2007 04:24:00 GMT
Thanks for the info Clinton and Paul... I'm not sure I would have
figured out those nuances on my own.

 

________________________________

From: Clinton Begin [mailto:clinton.begin@gmail.com] 
Sent: Thursday, January 04, 2007 10:04 PM
To: user-java@ibatis.apache.org
Subject: Re: iBatis Book - Lazy Loading Description

 

Paul is right, but I'd like to add a little more to the explanation:

With enhancement (CGLIB) you can lazy load properties of complex,
concrete or abstract types (as well as interfaces).  Without enhancement
(CGLIB), you can only lazy load properties of interface types. 

The reason is that Java's Dynamic Proxy facility only supports dynamic
implementation of interfaces.  It does not support dynamic class
extension -- which really sucks and for which there is NO good reason
(as proven by CGLIB). 

So that's the story.  I hope it helps.  

Clinton

On 1/4/07, MCCORMICK, Paul <Paul.McCORMICK@doir.wa.gov.au > wrote:

Setting lazyLoadingEnabled to true will allow the lazy loading 1 to many
relationships.  You don't have any 1 to many relationships in your code
below. 

Setting enhancementEnabled  to true will allow the lazy loading of 1 to
1 relationships. 

 

________________________________

From: Kuntz, Tim [mailto:tim_kuntz@pamperedchef.com] 
Sent: Friday, 5 January 2007 11:24 AM
To: user-java@ibatis.apache.org
Subject: iBatis Book - Lazy Loading Description

The new iBatis book describes lazy-loading as follows (pg 131).

"To use lazy loading, we need to edit the SqlMapConfig.xml file to
enable it by changing the lazyLoadingEnabled attribute to true in the
<setting> element. If you want to use the cglib enhanced version of lazy
loading, you will want to download it, add it to your application's
classpath, and change the enhancementEnabled attribute of the <setting>
element to true as well."

After setting up a sample similar to that in the book, I noticed that
lazy-loading only appears to work correctly if BOTH lazyLoadingEnabled
and enhancementEnabled are set to true. Running the following code
executes the selects as the objects are requested.

person = sqlMapper.queryForObject("Person.selectPerson"); // runs select
... from person

person.getAddress(); // runs select .. from address

person.getAddress().getState(); // runs select .. from state

Setting enhancementEnabled to false causes all of the select statements
to execute initially. Changing lazyLoadingEnabled to false doesn't
change the behavior.

person = sqlMapper.queryForObject("Person.selectPerson"); // runs all 3
select statements

person.getAddress();

person.getAddress().getState(); 

Is this correct behavior? If so, when would I benefit from
lazyLoadingEnabled = "true"?

I'm using iBatis version 2.3.0.677

Thanks,

Tim

"DISCLAIMER: This email, including any attachments, is intended only for
use by the addressee(s) and may contain confidential and/or personal
information and may also be the subject of legal privilege. If you are
not the intended recipient, you must not disclose or use the information
contained in it. In this case, please let me know by return email,
delete the message permanently from your system and destroy any copies. 

Before you take any action based upon advice and/or information
contained in this email you should carefully consider the advice and
information and consider obtaining relevant independent advice.

 


Mime
View raw message