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 Justin Stanczak <ri...@gmail.com> on 2008/01/02 23:54:41 UTC
MySQL LAST_INSERT_ID selectKey?
I'm currently using this to return the inserted objects generated key. These
are auto increment columns and I was wondering if this is correct. I notice
if I put the selectKey before the insert it returns the wrong key, is this
correct? Just wanted to verify.
<insert id="insertRole" parameterClass="Role">
INSERT INTO SAVVYLMS.SVV_ROLE (SVV_NAME,SVV_TYPE_ID,SVV_DESC) VALUES
(#name#,#type#,#description#);
<selectKey keyProperty="id" resultClass="long">
SELECT LAST_INSERT_ID();
</selectKey>
</insert>
--
"All that is necessary for the triumph of evil is that good men do nothing."
Edmund Burke
Re: MySQL LAST_INSERT_ID selectKey?
Posted by Justin Stanczak <ri...@gmail.com>.
I see using type="post", thanks.
On Jan 2, 2008 6:02 PM, Justin Stanczak <ri...@gmail.com> wrote:
> Cool, how do you do that?
>
>
> On Jan 2, 2008 5:59 PM, Nathan Maves <na...@gmail.com> wrote:
>
> > This is correct with mysql. You can also specify the selectKey to be a
> > "pre" or "post" then the placement of the code is not crucial.
> >
> > Nathan
> >
> >
> > On Jan 2, 2008 3:54 PM, Justin Stanczak < rizenine@gmail.com> wrote:
> >
> > > I'm currently using this to return the inserted objects generated key.
> > > These are auto increment columns and I was wondering if this is correct. I
> > > notice if I put the selectKey before the insert it returns the wrong key, is
> > > this correct? Just wanted to verify.
> > >
> > > <insert id="insertRole" parameterClass="Role">
> > > INSERT INTO SAVVYLMS.SVV_ROLE (SVV_NAME,SVV_TYPE_ID,SVV_DESC) VALUES
> > > (#name#,#type#,#description#);
> > > <selectKey keyProperty="id" resultClass="long">
> > > SELECT LAST_INSERT_ID();
> > > </selectKey>
> > > </insert>
> > >
> > > --
> > > "All that is necessary for the triumph of evil is that good men do
> > > nothing." Edmund Burke
> >
> >
> >
>
>
> --
> "All that is necessary for the triumph of evil is that good men do
> nothing." Edmund Burke
>
--
"All that is necessary for the triumph of evil is that good men do nothing."
Edmund Burke
Re: MySQL LAST_INSERT_ID selectKey?
Posted by Justin Stanczak <ri...@gmail.com>.
Cool, how do you do that?
On Jan 2, 2008 5:59 PM, Nathan Maves <na...@gmail.com> wrote:
> This is correct with mysql. You can also specify the selectKey to be a
> "pre" or "post" then the placement of the code is not crucial.
>
> Nathan
>
>
> On Jan 2, 2008 3:54 PM, Justin Stanczak < rizenine@gmail.com> wrote:
>
> > I'm currently using this to return the inserted objects generated key.
> > These are auto increment columns and I was wondering if this is correct. I
> > notice if I put the selectKey before the insert it returns the wrong key, is
> > this correct? Just wanted to verify.
> >
> > <insert id="insertRole" parameterClass="Role">
> > INSERT INTO SAVVYLMS.SVV_ROLE (SVV_NAME,SVV_TYPE_ID,SVV_DESC) VALUES
> > (#name#,#type#,#description#);
> > <selectKey keyProperty="id" resultClass="long">
> > SELECT LAST_INSERT_ID();
> > </selectKey>
> > </insert>
> >
> > --
> > "All that is necessary for the triumph of evil is that good men do
> > nothing." Edmund Burke
>
>
>
--
"All that is necessary for the triumph of evil is that good men do nothing."
Edmund Burke
Re: MySQL LAST_INSERT_ID selectKey?
Posted by Nathan Maves <na...@gmail.com>.
This is correct with mysql. You can also specify the selectKey to be a
"pre" or "post" then the placement of the code is not crucial.
Nathan
On Jan 2, 2008 3:54 PM, Justin Stanczak <ri...@gmail.com> wrote:
> I'm currently using this to return the inserted objects generated key.
> These are auto increment columns and I was wondering if this is correct. I
> notice if I put the selectKey before the insert it returns the wrong key, is
> this correct? Just wanted to verify.
>
> <insert id="insertRole" parameterClass="Role">
> INSERT INTO SAVVYLMS.SVV_ROLE (SVV_NAME,SVV_TYPE_ID,SVV_DESC) VALUES
> (#name#,#type#,#description#);
> <selectKey keyProperty="id" resultClass="long">
> SELECT LAST_INSERT_ID();
> </selectKey>
> </insert>
>
> --
> "All that is necessary for the triumph of evil is that good men do
> nothing." Edmund Burke