Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 3212 invoked from network); 27 Oct 2006 16:03:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 27 Oct 2006 16:03:38 -0000 Received: (qmail 34151 invoked by uid 500); 27 Oct 2006 16:03:46 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 34136 invoked by uid 500); 27 Oct 2006 16:03:46 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 34125 invoked by uid 99); 27 Oct 2006 16:03:46 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Oct 2006 09:03:46 -0700 X-ASF-Spam-Status: No, hits=2.5 required=10.0 tests=DNS_FROM_RFC_ABUSE,HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of nathan.maves@gmail.com designates 64.233.162.194 as permitted sender) Received: from [64.233.162.194] (HELO nz-out-0102.google.com) (64.233.162.194) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Oct 2006 09:03:32 -0700 Received: by nz-out-0102.google.com with SMTP id q3so629081nzb for ; Fri, 27 Oct 2006 09:03:11 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=Gav4dbTqOhOKcK904nyOf9A/YBEjw5exSPazQwvkTs1FyZt7xiWoL89aNZjYH8arm4cWb8zuBuczE4KP3F5N6LZmUOR+oWTL/wsVbFTMjr88H5BxvroUYoPmcQ42PDbpA/VRMPTniyqeatf1UfpgwyQq7rGuq+M0j6MdjNM1eus= Received: by 10.35.113.12 with SMTP id q12mr401847pym; Fri, 27 Oct 2006 08:52:37 -0700 (PDT) Received: by 10.35.26.13 with HTTP; Fri, 27 Oct 2006 08:52:37 -0700 (PDT) Message-ID: <2f55db670610270852x74059cc7md24fff3dc9b01f6d@mail.gmail.com> Date: Fri, 27 Oct 2006 09:52:37 -0600 From: "Nathan Maves" To: user-java@ibatis.apache.org Subject: Re: how to deal with one-to-many relationship? In-Reply-To: <200610270915105102378@gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_132185_25921316.1161964357387" References: <200610270915105102378@gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_132185_25921316.1161964357387 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 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 : > > > > > > select="getItemByOrderId" /> > > > > > > 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 > ------=_Part_132185_25921316.1161964357387 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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

------=_Part_132185_25921316.1161964357387--