ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Engel, Gregory A" <GAEn...@Tribune.com>
Subject RE: Object Oriented Loading Best Practice
Date Tue, 03 May 2005 16:56:47 GMT
You can of course do it in an "object oriented way" and use a single query
specifying the "c" objects resultmap.
<resultMap id="SomeMap" class="com.some.thing.a" groupBy="aId">
<result property ="id" column="id"/>
<result property="cList" resultMap="cResultMap"/>
This will get you an "a" object containing a list of "c's" (if that the way
the bean looks) provided 
that your query has all the columns needed by the "SomeMap" resultmap and
-----Original Message-----
From: Larry Meadors [mailto:larry.meadors@gmail.com]
Sent: Monday, May 02, 2005 5:41 PM
To: ibatis-user-java@incubator.apache.org; werner@sonoma.edu
Subject: Re: Object Oriented Loading Best Practice

I mean this is the nicest possible way: This is a silly question, and the
answer is "it depends".

If you have 1000 customers (A) and each of them have 1000 orders (B) and
each order has 25 line items (C), do you really need to load up 25,000,000

If so, buy a buttload of RAM, load them all in one uber-query, and be done
with it.

If not, use lazy loading.


On 5/2/05, Nic Werner < werner@sonoma.edu <mailto:werner@sonoma.edu> >

The question is more whether I should let the chain of objects populate
itself, or knowing A contains B contains C, populate them all in one
call. The former is more object oriented, while the latter is more

I need to load all the child objects, but instead of having one Select
block w/a ResultMap that calls the other Objects, I now have to write
another query and create a new ResultMap for all three objects. Or maybe 
I can include other ResultMaps?

The downside I see to that is that if I change an attribute in object B
or C, I have another query to update and ResultMap, whereas if I made
the individual call I would only need to update the Bean and its related 

The upside is of course, only one SQL call.

- Nic.

Brandon Goodin wrote:

>If you have no need to load the child objects then don't use a complex
>result in your resultMap.
>On 5/2/05, Nic Werner < werner@sonoma.edu <mailto:werner@sonoma.edu> >
>>    I have several objects in my program which have a bit of a 
>>hierarchy, ie A contains B, B contains C and so on. Each table in the DB
>>is linked to each other by a foreign key on a unique ID. I have iBATIS
>>populating each Bean by using a resultMap and calling on the object's 
>>Select statement to populate the encapsulated Bean. Meaning, if I try
>>and load info for B, it makes a call to the DB for B, and also for C.
>>My question is: Is this the best way to go about things? If I am loading 
>>A, it is going to create a call for A,B and C, where normally (w/o
>>IBATIS) I would just create a statement that contained a join of all
>>three tables on their unique IDs - and only one DB call. 
>>Let me know if I need to explain more.
>>- Nic.

View raw message