<!-Oracle SEQUENCE Example using .NET 1.1 System.Data.OracleClient --> 
<insert id="insertProduct-ORACLE" parameterClass="product"> 
  <selectKey resultClass="int" type="pre" property="Id" > 
     SELECT STOCKIDSEQUENCE.NEXTVAL AS VALUE FROM DUAL
  </selectKey> 
  insert into PRODUCT (PRD_ID,PRD_DESCRIPTION) values
(#id#,#description#) 
</insert>

<!- Microsoft SQL Server IDENTITY Column Example --> 
<insert id="insertProduct-MS-SQL" parameterClass="product"> 
  insert into PRODUCT (PRD_DESCRIPTION)
  values (#description#) 
 <selectKey resultClass="int" type="post" property="id" > 
   select @@IDENTITY as value
 </selectKey>
</insert>

<!-- MySQL Example -->
<insert id="insertProduct-MYSQL" parameterClass="product"> 
  insert into PRODUCT (PRD_DESCRIPTION)
  values (#description#) 
 <selectKey resultClass="int" type="post" property="id" > 
   select LAST_INSERT_ID() as value
 </selectKey>
</insert>

________________________________

From: Dorin Manoli [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, November 22, 2006 2:19 PM
To: [email protected]
Subject: RE: insert using a stored procedure



It depend what database engine you use. Code below is for MySQL

Use this code in xml map file under <insert> node and after insert query

<selectKey .... . . . >

                        select LAST_INSERT_ID() as value          

                  </selectKey>

 

________________________________

From: Bob Hanson [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, November 21, 2006 6:49 PM
To: [email protected]
Subject: insert using a stored procedure

 

What is the correct method to retrieve the Identity value of a newly
inserted row when using a stored procedure that performs an insert?

Thanks,
Bob

Reply via email to