ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Poitras Christian" <Christian.Poit...@ircm.qc.ca>
Subject RE: lazy loading
Date Thu, 15 Jun 2006 14:36:17 GMT
My answer may not be complete. But I will give you an idea.

If you enable lazy loading, the object that is loaded will be populated
normaly.
For all properties of this object that are loaded by another select and
that points to a non-final class will be in lazy mode.
The lazy object linked to the loaded object is, in fact, a subclass of
the original class that will call the select statement as soon as any
method is called upon it. So the lazy object will not be populated for
as long as no access is made to the lazy object.

If you have a result map like this.
<resultMap id="get-category-result" class="com.ibatis.example.Category">
   <result property="id" column="CAT_ID"/>
   <result property="description" column="CAT_DESCRIPTION"/>
   <result property="productList" column="CAT_ID"
select="getProductsByCatId"/>
</resultMap>

Then, productList will not pe populated until you access a method of
this List (unless productList is a final List of some sort).
If productList is an ArrayList, then iBatis will create a subclass of
ArrayList and store the sql statement to call to populate the List. As
you guess, this statement is run when you class any method of
productList.

Hope that helps.
Christian

-----Original Message-----
From: Dodo [mailto:j2eedodo@gmail.com] 
Sent: Wednesday, 14 June 2006 12:32
To: user-java@ibatis.apache.org
Subject: Re: lazy loading

Hi X,

That's not really lazy loading, it's dynamic conditional loading but I
guess it will do for the same thing.

According to page 7 and 9 of the same doc,

<settings
cacheModelsEnabled="true"
enhancementEnabled="true"
lazyLoadingEnabled="true"
maxRequests="128"
maxSessions="10"
maxTransactions="5"
useStatementNamespaces="false"
/>

lazyLoadingEnabled is 'true' by default, exactly how does this lazy
loading work?

The doc seems to lack in this. For example,

<resultMap id="get-category-result" class="com.ibatis.example.Category">
   <result property="id" column="CAT_ID"/>
   <result property="description" column="CAT_DESCRIPTION"/>
   <result property="productList" column="CAT_ID" select=" 
getProductsByCatId"/>
</resultMap>

.......

<statement id="getProductsByCatId" parameterClass="int"
resultMap="get-product-result">
   select * from PRODUCT where PRD_CAT_ID = #value# </statement>

Now if productList contains 10000 products, does resultMap
'get-category-result' load productList by lazy loading when called??

Or under what condition, does default lazyLoadingEnabled='true' work?

Thanks,



----- Original Message -----
From: "xianwinwin" <xianwinwin@gmail.com>
To: <user-java@ibatis.apache.org>
Sent: Thursday, June 15, 2006 2:52 PM
Subject: Re: lazy loading


>
> hi there, i just had the same problem and i found it in the tutorial
at:
>
>
http://people.apache.org/dist/ibatis/ibatis.java/docs/iBATIS-SqlMaps-2.p
df
>
> page 36
> hope this helps
> --
> View this message in context: 
> http://www.nabble.com/lazy-loading-t1789831.html#a4876489
> Sent from the iBATIS - User - Java forum at Nabble.com.
> 



Mime
View raw message