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 16:34:11 GMT
You are right.
The List of Items is only populated (and you'll sure wait a long time!)
when the 2nd call is made.
For sure, if you are to populate so many objects in one List, you will
have to find a better way to populate only a part of it.

Also, make sur the the List implementation you are using is not final.
As far as I known, there are no "final" Lists in java.util.

Additionnal note : be carefull of your getter and setter in Category.
They must only set and get without any kind of validation to make sure
everything works right (I'm pretty sure you do it correctly anwyay...).

Happy time saving!
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

Cool, Poitras,

Just some clarification.

So if I retrieve a Category object that has an ArrayList of  1 million
Item objects as below

  Category cat = dao.getCategory( new Long(1) );

this call shud return very quickly as an ArrayList of 1 million Item
objects
will not be populated.

However, if I access Arraylist thru getter of Category as below and try
to
access list thru its  methods as u say

  List list = cat.getItemList();  // 1st line
  Item item = (Item)list.get(4);  // 2nd line

Then it will indeed load those 1 million objects, right??

I assume its the 2nd line above that will actually load
the objects from database. Correct me if wrong.

If this is the case, it wud be too coool! As this will allow me
to pass the list in to methods, presentation tier, different objects
and load data only when actually needed.



Thanks,

Samuel 


Mime
View raw message