You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Nathan Maves <na...@gmail.com> on 2006/10/05 23:43:01 UTC

Multiple results maps

Here is the setup....

two tables invoice and user

The invoice table has two columns, one for the sales person and one for the
customer.  These map to their respective ids in the user table.  To avoid
the 2N+1 problem I join the tables.

  <resultMap id="invoiceResult" class="invoice">
    ...
    <result property="customer" resultMap="user.userResult" />
    <result property="salesperson" resultMap="user.userResult"/>
  </resultMap>

  <select id="select" resultMap="invoiceResultMap" parameterClass="string">
    select
          *
    from invoice, user cusotmer, user salesperson
    where
        invoice.id = #value#
        and invoice.customer = customer.id
        and invoice.sales = salesperson.id
  </select>

I don't believe that this will work because the columns are identical in the
two user tables.  Any ideas on how to solve this cleanly. I know that I can
rename the columns, and then put the unique name in the resultmap  but I was
trying to avoid this.

Nathan

RE: Multiple results maps

Posted by Poitras Christian <Ch...@ircm.qc.ca>.
Try returning the columns in the order of your result map.
I can't say it could work, but it's worth trying.
 
Christian

________________________________

From: Nathan Maves [mailto:nathan.maves@gmail.com] 
Sent: Thursday, 05 October 2006 17:43
To: user-java@ibatis.apache.org
Subject: Multiple results maps


Here is the setup....

two tables invoice and user

The invoice table has two columns, one for the sales person and one for
the customer.  These map to their respective ids in the user table.  To
avoid the 2N+1 problem I join the tables. 

  <resultMap id="invoiceResult" class="invoice">
    ...
    <result property="customer" resultMap="user.userResult" />
    <result property="salesperson" resultMap=" user.userResult"/>
  </resultMap>

  <select id="select" resultMap="invoiceResultMap"
parameterClass="string">
    select
          *
    from invoice, user cusotmer, user salesperson 
    where 
        invoice.id = #value#
        and invoice.customer = customer.id
        and invoice.sales = salesperson.id
  </select>

I don't believe that this will work because the columns are identical in
the two user tables.  Any ideas on how to solve this cleanly. I know
that I can rename the columns, and then put the unique name in the
resultmap  but I was trying to avoid this. 

Nathan