Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 34779 invoked from network); 2 Jan 2008 22:59:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Jan 2008 22:59:50 -0000 Received: (qmail 58427 invoked by uid 500); 2 Jan 2008 22:59:38 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 58412 invoked by uid 500); 2 Jan 2008 22:59:38 -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 58400 invoked by uid 99); 2 Jan 2008 22:59:38 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Jan 2008 14:59:38 -0800 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of nathan.maves@gmail.com designates 209.85.146.181 as permitted sender) Received: from [209.85.146.181] (HELO wa-out-1112.google.com) (209.85.146.181) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Jan 2008 22:59:15 +0000 Received: by wa-out-1112.google.com with SMTP id j5so10481521wah.24 for ; Wed, 02 Jan 2008 14:59:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; bh=EzfdJEf5axdHKGppA0TbSts1xAU6X02KFNuuBglbxOI=; b=lViKoyueN7uEdkWUv+frAonmk8S5b7pGFJpQiKEVFVfDYFBjtyo57gAjok3X2YlAxobL2wysLVMghGs1ZjG96jMrMDiw63YGQRZbd8ysotYBpXGf21Kb8WsfH1RqkpGIjw8DZOw5ThlQZ2ZVHXpDE9xrcPwwn/QF1qUgXRuqMfk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=rrcPJAX0UXZfR8aC9oJnpqBQzE8xmpRX0THp5xAUhHiIT4hqX0t/7JVHNcKekY6snxS4QINC4Y6qkYo0ACa4ubJy6pvJblmEQfMh8QZYwPyyDB6xryc0MLGvVpn8QSZ+RpD5z8rjwH7l8tu/0XZtUKSeud8i8mICfYIRcaIqQ9Y= Received: by 10.115.108.1 with SMTP id k1mr16234246wam.141.1199314760006; Wed, 02 Jan 2008 14:59:20 -0800 (PST) Received: by 10.114.121.3 with HTTP; Wed, 2 Jan 2008 14:59:19 -0800 (PST) Message-ID: <2f55db670801021459i51c10a9dub04d3b3a898793bb@mail.gmail.com> Date: Wed, 2 Jan 2008 15:59:19 -0700 From: "Nathan Maves" To: user-java@ibatis.apache.org Subject: Re: MySQL LAST_INSERT_ID selectKey? In-Reply-To: <3887f8450801021454q1779beaew5ff6d1f8b8a3011d@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_28565_32469200.1199314760000" References: <3887f8450801021454q1779beaew5ff6d1f8b8a3011d@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_28565_32469200.1199314760000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline This is correct with mysql. You can also specify the selectKey to be a "pre" or "post" then the placement of the code is not crucial. Nathan On Jan 2, 2008 3:54 PM, Justin Stanczak wrote: > I'm currently using this to return the inserted objects generated key. > These are auto increment columns and I was wondering if this is correct. I > notice if I put the selectKey before the insert it returns the wrong key, is > this correct? Just wanted to verify. > > > INSERT INTO SAVVYLMS.SVV_ROLE (SVV_NAME,SVV_TYPE_ID,SVV_DESC) VALUES > (#name#,#type#,#description#); > > SELECT LAST_INSERT_ID(); > > > > -- > "All that is necessary for the triumph of evil is that good men do > nothing." Edmund Burke ------=_Part_28565_32469200.1199314760000 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline This is correct with mysql.  You can also specify the selectKey to be a "pre" or "post" then the placement of the code is not crucial.

Nathan

On Jan 2, 2008 3:54 PM, Justin Stanczak < rizenine@gmail.com> wrote:
I'm currently using this to return the inserted objects generated key. These are auto increment columns and I was wondering if this is correct. I notice if I put the selectKey before the insert it returns the wrong key, is this correct? Just wanted to verify.

<insert id="insertRole" parameterClass="Role">
  INSERT INTO SAVVYLMS.SVV_ROLE (SVV_NAME,SVV_TYPE_ID,SVV_DESC) VALUES (#name#,#type#,#description#);
  <selectKey keyProperty="id" resultClass="long">
  SELECT LAST_INSERT_ID();
  </selectKey>
  </insert>

--
"All that is necessary for the triumph of evil is that good men do nothing."   Edmund Burke

------=_Part_28565_32469200.1199314760000--