|
>> Use it carefully - in case of multiple inserts >> you could get wrong @@IDENTITY value. Good catch! I can’t risk getting the wrong identity when multiple
inserts are happening. In that case, I will be using your version: <selectKey resultClass="int" type="post"
property="Id"> SELECT cast(IDENT_CURRENT('dbo.Person') as int) AS Id </selectKey> Instead of this: <selectKey property="Id" resultClass="int"> SELECT cast(@@IDENTITY as int) as value </selectKey> Do you recommend using SQL Server’s auto-increment feature? Gary P. Russo MSN IM: [EMAIL PROTECTED] -----Original Message----- > However, I decided to use Pablo's code because there is no hard
coded > table name. I don't like it - but it is placed near main insert statement where table name is hardcoded too. > <selectKey property="IdUsuario"
resultClass="int"> > SELECT cast(@@IDENTITY as int) as value > </selectKey> Use it with carefull - in case of multipile inserts you could get wrong @@IDENTITY value. E.g. 1. application1 inserts record to the Table1 (using iBATIS) 2. application2 inserts record to the Table2 (using anything to access database) 3. selectKey performed for the app1 insert ATTENTION! 4. selectKeyPerformed for the app2 insert If thing goes as in the example above you'll get wrong ID for inserted object in the app1. Good luck. |
- auto-key generation example Russo, Gary
- Re: auto-key generation example oleksa borodie
- RE: auto-key generation example Pablo López
- RE: auto-key generation example Russo, Gary
- Re: auto-key generation example oleksa borodie
- RE: auto-key generation example Pablo López
- RE: auto-key generation example Russo, Gary
- RE: auto-key generation example Russo, Gary

