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.

Cheers,
Clinton



On 9/6/05, Farsi, Reza <[EMAIL PROTECTED]> 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

Reply via email to