Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 56874 invoked from network); 19 Jul 2007 13:16:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Jul 2007 13:16:20 -0000 Received: (qmail 48701 invoked by uid 500); 19 Jul 2007 13:15:54 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 48687 invoked by uid 500); 19 Jul 2007 13:15:54 -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 48676 invoked by uid 99); 19 Jul 2007 13:15:54 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Jul 2007 06:15:54 -0700 X-ASF-Spam-Status: No, hits=1.6 required=10.0 tests=DATE_IN_PAST_96_XX,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of dcmoeller@gmx.de designates 213.165.64.20 as permitted sender) Received: from [213.165.64.20] (HELO mail.gmx.net) (213.165.64.20) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 19 Jul 2007 06:15:51 -0700 Received: (qmail invoked by alias); 19 Jul 2007 13:15:29 -0000 Received: from dslb-084-059-015-143.pools.arcor-ip.net (EHLO [192.168.1.41]) [84.59.15.143] by mail.gmx.net (mp029) with SMTP; 19 Jul 2007 15:15:29 +0200 X-Authenticated: #18303827 X-Provags-ID: V01U2FsdGVkX1/Hd3d7RM3H7zGWN8WZfU1/yIAyUMQB8LV87xqQWV OV4xHt+pqFEpdF Message-ID: <4698B2E3.8080009@gmx.de> Date: Sat, 14 Jul 2007 13:26:27 +0200 From: =?ISO-8859-1?Q?=22Dr=2E_Christian_M=F6ller=22?= User-Agent: Thunderbird 1.5.0.12 (X11/20060911) MIME-Version: 1.0 To: user-java@ibatis.apache.org Subject: Re: select Key not working giving error. References: <872487.84782.qm@web8715.mail.in.yahoo.com> <4697206F.60503@gmx.de> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Y-GMX-Trusted: 0 X-Virus-Checked: Checked by ClamAV on apache.org Hi, in this case and if I understand the iBatis feature correctly the only thing to change is the type attribute of the selectKey element to "pre". This will fetch the sequence value in advance returning it in the same way. Greetings Christian Jeff Butler schrieb: > Guys - @@identity and a sequence are two completely different things. > > With @@identity, you get the key AFTER the record is inserted and it > does not need to be mapped - because iBATIS will return it to you as a > result of the insert() statement. > > Sequences are different - you must get the new key BEFORE the record > is inserted. The returned value needs to be stored somewhere. You'll > either need to map it to a field in your object, or make the sequence > call directly in the insert statement as Sivaranjani described. > > Jeff Butler > > On 7/13/07, *Christian M�ller* > wrote: > > felix thomas schrieb: > > hi, > > > > I am not able to understand if the key are not > > mapped , how is it working for you. > > Before switching to iBatis I've coded it the usual JDBC-way: After > executing the INSERT I've triggered the SELECT (given in the > "selectKey" > element) on the *same* Connection to retrieve the auto-incremented > value. (Some JDBC drivers support > java.sql.Statement.getGeneratedKeys(), > but this does not seem the way iBatis handles this feature.) > > I think iBatis handles it the same way. Think of the "selectKey" > element > as something like a "select" element with the given resultClass > attribute (and without any parameterMap cause of the lack of any > parameters, of course): > > > > This SELECT could be handled just like I've decribed in my > posting. That > way the usual semantics of the result of sqlMapClient.insert() > changes: > You do not receive the number of updates the INSERT yields but the > result of executing the given SELECT statement. > > > Can anyone give an example done in Oracle for this > > kind of situation. > > Unfortunately, I do not have an Oracle DB at hand. But the iBatis > developer guide shows an example handling Oracle specifics at page > 22/23. > > Greetings > > Christian > > > --- Christian M�ller > wrote: > > > >> Hi, > >> > >> I myself are using this kind of iBATIS config with a > >> Sybase DB: > >> > >> >> parameterClass="contact"> > >> insert into CONTACT (PROP1, ...) values > >> (#property1#, ...) > >> > >> select @@IDENTITY > >> > >> > >> > >> "@@IDENTITY" is the Sybase way to retrieve the > >> auto-incremented value of > >> the primary key column. > >> > >> As you can see: There is no mapping of the resulting > >> key to a property > >> of the parameter class. I'm retrieving the > >> auto-incremented key by > >> executing > >> > >> Long generatedKey = (Long) > >> sqlMapClient.insert("insertContact", contact) > >> > >> Hope this will guide you to a working solution. > >