Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 24345 invoked from network); 5 Jan 2007 15:25:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Jan 2007 15:25:04 -0000 Received: (qmail 68919 invoked by uid 500); 5 Jan 2007 15:25:08 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 68907 invoked by uid 500); 5 Jan 2007 15:25:08 -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 68896 invoked by uid 99); 5 Jan 2007 15:25:08 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Jan 2007 07:25:08 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of larry.meadors@gmail.com designates 64.233.184.231 as permitted sender) Received: from [64.233.184.231] (HELO wr-out-0506.google.com) (64.233.184.231) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Jan 2007 07:24:59 -0800 Received: by wr-out-0506.google.com with SMTP id i28so987970wra for ; Fri, 05 Jan 2007 07:24:37 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=jZUWC70lT98M8pTkb+AhwyfxlYCspLKVl1XXhYue2bHzRO8xiIfBVqeeMhySXOvOYEZZVt6ea7dmWOY0f/2YtZFL2hf7PfUtEjJ4hm0vSQXI7ncxjn1h+qUGydf0B55QV59fRHdVyoI8+kFw8agoHVyoD6kN1BW4Uyii6izByDs= Received: by 10.90.115.4 with SMTP id n4mr867846agc.1168010675952; Fri, 05 Jan 2007 07:24:35 -0800 (PST) Received: by 10.90.35.4 with HTTP; Fri, 5 Jan 2007 07:24:35 -0800 (PST) Message-ID: Date: Fri, 5 Jan 2007 08:24:35 -0700 From: "Larry Meadors" Reply-To: lmeadors@apache.org Sender: larry.meadors@gmail.com To: user-java@ibatis.apache.org Subject: Re: Data insertion into Parent and Child table -- How to do this while batch insert in IBatis In-Reply-To: <002801c730d3$6360cef0$4514a8c0@ZSPL.local> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <002801c730d3$6360cef0$4514a8c0@ZSPL.local> X-Google-Sender-Auth: c6c61292de1a24ca X-Virus-Checked: Checked by ClamAV on apache.org IIRC, your batch will be lots faster in a transaction, and if you do this: start transaction insert parent start batch insert children end batch end transaction I think you'll be OK. Larry On 1/5/07, Deepinder wrote: > > > > > > > Hi, > > > > Is it possible to insert data into a parent table and then use the generated > primary key to insert into a child table. > > I need to do this during a batch insert as it is necessary(performance). > > > > Thanking you for any lead that may be provided in solving this problem.(I > spent a day , on this problem J) > > > > The sample code below has a comment specifying where the problem is > > > > public void batchInsertTable( > > final List beanList) { > > > > > getSqlMapClientTemplate().execute(new > SqlMapClientCallback() { > > > > public Object > doInSqlMapClient(SqlMapExecutor executor) > > throws > SQLException { > > > > executor.startBatch(); > > > > for (int i = 0; i < > beanList.size(); i++) { > > Integer > primaryKey = (Integer)executor.insert("populateTable", > > > beanList.get(i)); > > > //use primaryKey for storing info in child table > > //Problem is that in batch insert the primarykey value returned is random > number (not the //one in database) > > } > > > > executor.executeBatch(); > > return null; > > } > > > > }); > > > > }