ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steven Pannell <steven.pann...@zooplus.com>
Subject RE: Getting the generate primary key
Date Thu, 17 Mar 2005 16:25:12 GMT
Looks like I have to use the sequence.nextval approach and insert it that
way (by-pass the trigger).  Not really a big problem.

Thanks!

-----Original Message-----
From: Rafiq, Adnan [mailto:arafiq@carreker.com]
Sent: 17 March 2005 17:12
To: 'ibatis-user-java@incubator.apache.org'
Subject: RE: Getting the generate primary key


We have always used the table-driven approach for generating keys (i.e. a
database table that provides the next id). I am currently comtemplating
moving to identity columns in MS SQL Server and let the database handle the
id generation.

Any pros and cons (apart from the usual portability concerns) with this
approach? Is performance, with SQL Server, acceptable when inserting
thousands of rows in this fashion?

-----Original Message-----
From: Akins, Greg [mailto:gakins@amervideo.com]
Sent: Thursday, March 17, 2005 10:08 AM
To: ibatis-user-java@incubator.apache.org
Subject: RE: Getting the generate primary key


In Oracle, is that going to be difficult if you're using a trigger to
create the ID?

Using a select from sequence insure that you have the same ID as the
insert statement is going to receive.

Using @@identiy and select Last_insert_id() guarantee (I think) that the
value returned was the one used by your insert statement.

However, in Oracle, you'll have to select the max(id) after the insert
and there is no guarantee that you're getting the same id, right?

-----Original Message-----
From: James, Steven [mailto:Steven.James@logicacmg.com] 
Sent: Thursday, March 17, 2005 11:03 AM
To: ibatis-user-java@incubator.apache.org
Subject: RE: Getting the generate primary key


you need to add the 
<selectKey resultClass="int" keyProperty="id" > 
			select LAST_INSERT_ID()  
		</selectKey>
above is for mysql just change to olacle specific code. etc

steve

-----Original Message-----
From: Steven Pannell [mailto:steven.pannell@zooplus.com]
Sent: Thu 3/17/2005 3:52 PM
To: 'ibatis-user-java@incubator.apache.org'
Subject: Getting the generate primary key
 
Hi,

I want to get the automatically generated key from a newly inserted row
(my oracle database handles the generation of the key via a trigger).  

I followed the docs but it does not appear to be working.

SqlMap:

<insert id="writeOrder" parameterClass="Order"  >
	INSERT INTO
	ORDERS(order_price)
	values(#orderPrice#)
</insert>

Code:

Long id = (Long)client.insert(new SqlMapId("writeOrder"),order);


The returned value is always null. but I want the primary key id.

am I doing anything wrong here (using ibatis 2.0.9.496)  I'm sure when i
tried this on an earlier version if iBatis it was working.

Thanks,
Steve.

Mime
View raw message