You are both showing me how to use the insert element which I already know
how to do.

I thought stored procedures have to use the procedure element.

According to SqlMap.xsd, selectKey is not a valid child element of
procedure.

On 11/22/06, Senthilmurugan, ANGLER - EIT <[EMAIL PROTECTED]>
wrote:

 <!—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