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 "Beary, Nick (EHQ)" <NB...@express-scripts.com> on 2009/08/28 16:56:16 UTC

Insert statement returns generated key

Hello, I looked around for an answer to this but didn't see anything.  To insert objects in our database, I have to use a macro that returns the key of the newly inserted object.  This means that the entirety of my insert statement is located in the selectKey section.  Because an SQL statement is required in the PCDATA section outside of <selectKey>, I just put a ; there.  So it looks like this:

<insert id="insert-xxx" parameterClass="xxx">
        ;
<selectKey resultClass="int" keyProperty="ID">
                exec insert_macro(...)
        </selectKey>
</insert>

Does anybody know a more elegant/less hacky solution to this?

We are using Teradata 12.0.

Thanks!
Nick




RE: Insert statement returns generated key

Posted by Jose Lora <Jo...@meredith.com>.
Thanks for sharing this Nick. Not good for documenting your intentions
but could you also use a mapped SELECT statement instead?

 

From: Clinton Begin [mailto:clinton.begin@gmail.com] 
Sent: Friday, August 28, 2009 11:02 AM
To: user-java@ibatis.apache.org
Subject: Re: Insert statement returns generated key

 

I don't, but that's pretty awesome that you figured that out and it
works... LOL.  :-)

Clinton

On Fri, Aug 28, 2009 at 8:56 AM, Beary, Nick (EHQ)
<NB...@express-scripts.com> wrote:

Hello, I looked around for an answer to this but didn't see anything.
To insert objects in our database, I have to use a macro that returns
the key of the newly inserted object.  This means that the entirety of
my insert statement is located in the selectKey section.  Because an SQL
statement is required in the PCDATA section outside of <selectKey>, I
just put a ; there.  So it looks like this:

<insert id="insert-xxx" parameterClass="xxx">

        ;

<selectKey resultClass="int" keyProperty="ID">

                exec insert_macro(...)

        </selectKey>

</insert>

 

Does anybody know a more elegant/less hacky solution to this?

 

We are using Teradata 12.0.

 

Thanks!

Nick

 

 

 

 


Re: Insert statement returns generated key

Posted by Larry Meadors <la...@gmail.com>.
Couldn't you call it just as a procedure?

Larry


On Fri, Aug 28, 2009 at 9:02 AM, Clinton Begin<cl...@gmail.com> wrote:
> I don't, but that's pretty awesome that you figured that out and it works...
> LOL.  :-)
>
> Clinton
>
> On Fri, Aug 28, 2009 at 8:56 AM, Beary, Nick (EHQ)
> <NB...@express-scripts.com> wrote:
>>
>> Hello, I looked around for an answer to this but didn’t see anything.  To
>> insert objects in our database, I have to use a macro that returns the key
>> of the newly inserted object.  This means that the entirety of my insert
>> statement is located in the selectKey section.  Because an SQL statement is
>> required in the PCDATA section outside of <selectKey>, I just put a ;
>> there.  So it looks like this:
>>
>> <insert id="insert-xxx" parameterClass="xxx">
>>         ;
>> <selectKey resultClass="int" keyProperty="ID">
>>                 exec insert_macro(…)
>>         </selectKey>
>> </insert>
>>
>> Does anybody know a more elegant/less hacky solution to this?
>>
>> We are using Teradata 12.0.
>>
>> Thanks!
>> Nick
>>
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Insert statement returns generated key

Posted by Clinton Begin <cl...@gmail.com>.
I don't, but that's pretty awesome that you figured that out and it works...
LOL.  :-)

Clinton

On Fri, Aug 28, 2009 at 8:56 AM, Beary, Nick (EHQ) <
NBeary@express-scripts.com> wrote:

>  Hello, I looked around for an answer to this but didn’t see anything.  To
> insert objects in our database, I have to use a macro that returns the key
> of the newly inserted object.  This means that the entirety of my insert
> statement is located in the selectKey section.  Because an SQL statement is
> required in the PCDATA section outside of <selectKey>, I just put a ;
> there.  So it looks like this:
>
> <insert id=*"insert-**xxx**"* parameterClass=*"**xxx**"*>
>         ;
> <selectKey resultClass=*"int"* keyProperty=*"ID"*>
>                 exec insert_macro(…)
>         </selectKey>
> </insert>
>
> Does anybody know a more elegant/less hacky solution to this?
>
> We are using Teradata 12.0.
>
> Thanks!
> Nick
>
>
>
>