ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Akins, Greg" <gak...@amervideo.com>
Subject RE: Getting the generate primary key
Date Thu, 17 Mar 2005 16:19:21 GMT
Just talked to my DBA.

First... Do you have to keep using the trigger? You probably saw from
the docs that you can do a select nextval from the sequence before the
insert in Ibatis, rather than using the trigger.

However, if you have legacy "issues", my DBA suggested you add a column
to the table that stores something unique about YOUR record so you can
check max(id) where uniquekey = "MINE" (Maybe a session id?)  He
couldn't think of an Oracle function synonymous with SQLServer's
@@identity, or MySQL's last_inser_id()

-----Original Message-----
From: Steven Pannell [mailto:steven.pannell@zooplus.com] 
Sent: Thursday, March 17, 2005 11:08 AM
To: 'ibatis-user-java@incubator.apache.org'
Subject: RE: Getting the generate primary key



Yes, that's right.  Not a good idea to use max(id) in oracle at all.



-----Original Message-----
From: Akins, Greg [mailto:gakins@amervideo.com]
Sent: 17 March 2005 17:08
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