ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "xiuxiu" <xiuxiu.luo.x...@gmail.com>
Subject how to deal with one-to-many relationship?
Date Fri, 27 Oct 2006 01:15:15 GMT
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