Added by Mario Alberto Montoya MartÃnez, last edited by Mario Alberto Montoya MartÃnez on Apr 17, 2006
(view change)
It seems there's an omition in the iBATIS SQL Maps Documentation. According to it the selectKey stanza would have the following syntax:
<selectKey resultClass="int"> SELECT SEQUENCENAME.NEXTVAL AS ID FROM DUAL </selectKey>
But it won't work as it always inserts zero in your insert table in the id column. This would cause a Primary Key constraint violated, if you defined one.
The correct syntax is:
<selectKey resultClass="int" keyProperty="id"> SELECT SEQUENCENAME.NEXTVAL AS ID FROM DUAL </selectKey>
With this new attribute (keyProperty) your're telling iBATIS that "id" is the name for you inline-parameter in your insert query. For example:
<insert id="insertProduct-ORACLE" parameterClass="com.domain.Product"> <selectKey resultClass="int" keyProperty="id"> SELECT STOCKIDSEQUENCE.NEXTVAL AS ID FROM DUAL </selectKey> insert into PRODUCT (PRD_ID,PRD_DESCRIPTION) values (#id#,#description#) </insert>
Here, #id# is the inline-parameter.
Please, correct me if I'm wrong, since I'm not an iBATIS developer, just a Java user.
Regards!
