ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Clinton Begin <clinton.be...@gmail.com>
Subject Re: How many select calls for Loading an object and referenced objects
Date Tue, 06 Sep 2005 13:58:06 GMT
Yes, you can use a join and avoid the N+1 selects problem. I'd point you to 
our FAQ, but Confluence is broken right now. :-/

There is some basic documentation in the developer guide. Have a look there 
first (look for groupBy and resultMap). If you still have questions after 
reading the docs, then feel free to ask.


On 9/6/05, Farsi, Reza <Reza.Farsi@sungard.de> wrote:
> Hi,
> I'm new to iBATIS.
> Following question:
> When a class is referencing an another class, how can I load the 
> referencing class with only one select. Imagine, you have classes Fund and 
> Transaction. Transaction has in database a filed for fund_id that references 
> a Fund.
> At the Moment, I have two mapping files for Fund and Transaction. In the 
> mapping for Fund I've a select as follows:
> <select id="getFundById" resultMap="fund" parameterClass="int">
> select * from fund where id=#value#
> </select>
> In mapping file for transaction I've the following statements:
> <resultMap id="tansaction" class="transaction">
> <result property="id" column="id"/>
> <result property="fund" select="getFundById" column="fund_id"/>
> </resultMap>
> <select id="getAllTransactions" resultMap="transaction">
> SELECT * FROM transaction
> </select>
> I assume, that the call of getAllTransactions leads to call of both 
> selects. If I'm right, is it possible to optimize the select call by mapping 
> the referencing and referenced objects in only one select call using join?
> Thanks and Regards
> Reza

View raw message