ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Maves" <nathan.ma...@gmail.com>
Subject Re: how to deal with one-to-many relationship?
Date Fri, 27 Oct 2006 15:52:37 GMT
First off as a new user please take some time to read through the Developers
Guide that can be found on the main page.  Second what you are doing is the
classic problem of 1:M.  Your current code also has the N+1 problem.  You
will query once for you main select and N number of times for each row the
first query returns.  Once again please consult the developers guide.  It
has examples of how to avoid and solve these problems.

Nathan

On 10/26/06, xiuxiu <xiuxiu.luo.xiao@gmail.com> wrote:
>
>  Hi, All,
>
>     I am a newer to ibatis And met some problems when I deal with
> one-to-many relationship.
>     There are two classes:
> public class Order {
>       private int id;
>       private double total;
>     private Set orderLineItems = new HashSet();
> }
> public class OrderLineItem
> {
>     private int id;
>     private int lineItemPrice;
>     private Order order;
> }
>
> One Order instance contains a group of OrderLineItem instances;
> I use resultMap to do the select operation such as :
>
> <resultMap id="get-order-result" class="order">
>   <result property="id" column="order_id" />
>   <result property="total" column="total" />
>   <result property="userName" column="username" />
>   <result property="orderLineItems" column="order_id"
>    select="getItemByOrderId" />
>  </resultMap>
> <select id="findOrderById" resultMap="get-order-result"
>   parameterClass="java.lang.Integer">
>   select order_id,
>          total,
>          username
>   from   orders
>   where  order_id = #id#
>  </select>
>
>  <select id="getItemByOrderId" resultClass="orderLineItem"
>   parameterClass="int">
>   select orderlineitem_id,
>          lineitemprice,
>          description
>   from   orderlineitem
>   where  order_id = #id#
>  </select>
>
> but I couldn't find the way to set OrderLineItem.order.
> Please have a look and help me if possible.
>
> Luo
>
>
>  ------------------------------
>  xiuxiu
> 2006-10-27
>

Mime
View raw message