You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by PLC_David <sp...@gmx.de> on 2008/09/03 10:52:49 UTC

selectKey twice

Hello,

i have a problem with an insert.
I need two generated ids to avoid an update after the insert.

My Question is: Is it possible to use two selectKey Tags.
Ibatis throws no exception, instead I get the correct id at the first
selectKey and 0 at the second selectKey. 


<insert id="insertCd" parameterClass="cd">
		<selectKey resultClass="int" keyProperty="id">
			SELECT COALESCE(max(ID)+1,1) from CD
		</selectKey>	
		<selectKey resultClass="int" keyProperty="db.id">
			SELECT COALESCE(max(ID)+1,1) from DB
		</selectKey>)
                INSERT INTO .... (ID, DB_ID, ....)
		VALUES (#id#, #db.id#, ...)
</insert>
-- 
View this message in context: http://www.nabble.com/selectKey-twice-tp19285322p19285322.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: selectKey twice

Posted by PLC_David <sp...@gmx.de>.
hi Larry,

thanks for your post. I use DB2 and at this time it's a single threaded
system.
But I don't understand why ibatis throws no exception and accepts this
mapping.

David



Larry Meadors wrote:
> 
> No, I think it only runs one of them...but are you really generating
> two new keys?
> 
> If you are, don't do it this way unless it is and will always be a
> single threaded system, and only if your database can't do
> auto-incrementing ids - what database are you using?
> 
> Larry
> 
> 

-- 
View this message in context: http://www.nabble.com/selectKey-twice-tp19285322p19289110.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: selectKey twice

Posted by Larry Meadors <la...@gmail.com>.
No, I think it only runs one of them...but are you really generating
two new keys?

If you are, don't do it this way unless it is and will always be a
single threaded system, and only if your database can't do
auto-incrementing ids - what database are you using?

Larry


On Wed, Sep 3, 2008 at 2:52 AM, PLC_David <sp...@gmx.de> wrote:
>
> Hello,
>
> i have a problem with an insert.
> I need two generated ids to avoid an update after the insert.
>
> My Question is: Is it possible to use two selectKey Tags.
> Ibatis throws no exception, instead I get the correct id at the first
> selectKey and 0 at the second selectKey.
>
>
> <insert id="insertCd" parameterClass="cd">
>                <selectKey resultClass="int" keyProperty="id">
>                        SELECT COALESCE(max(ID)+1,1) from CD
>                </selectKey>
>                <selectKey resultClass="int" keyProperty="db.id">
>                        SELECT COALESCE(max(ID)+1,1) from DB
>                </selectKey>)
>                INSERT INTO .... (ID, DB_ID, ....)
>                VALUES (#id#, #db.id#, ...)
> </insert>
> --
> View this message in context: http://www.nabble.com/selectKey-twice-tp19285322p19285322.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>