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 Doug Flex <do...@yahoo.com> on 2008/08/07 21:45:58 UTC
Can Insert mapped statement be reuse?
Hi,
I want to get the primary key (which is auto increment) return to my object after the insert statement. I don't want to modify the generated insert statement from Sqlmap because I want to continue to take advantage of the generated code for future changes in the database. Is there a way to reuse the insert statement similiar to the way you re-use SQL?
1) This is Abator generated code
<insert id="abatorgenerated_insert" parameterClass="MyClass">
insert sql statement here ....
</insert>
2) this is manual code is my attempt to reuse the generated insert statement in step 1. But this doesn't work. Is there a way to do this correctly?
<insert id="insert_withReturnId" parameterClass="MyClass">
<include refid="abatorgenerated_insert" /> <<-- THIS DOESN'T WORK
<selectKey resultClass="int" keyProperty="Id" type="post">
SELECT LAST_INSERT_ID()
</selectKey>
</insert>
Re: Can Insert mapped statement be reuse?
Posted by Jeff Butler <je...@gmail.com>.
If you setup your (a)ibator configurations using the <generatedKey> element,
then (a)ibator will generate the <selectKey> for you. This is the best
solution, I think.
Jeff Butler
On Thu, Aug 7, 2008 at 2:45 PM, Doug Flex <do...@yahoo.com> wrote:
> Hi,
>
> I want to get the primary key (which is auto increment) return to my object
> after the insert statement. I don't want to modify the generated insert
> statement from Sqlmap because I want to continue to take advantage of the
> generated code for future changes in the database. Is there a way to reuse
> the insert statement similiar to the way you re-use SQL?
>
> 1) This is Abator generated code
> <insert id="abatorgenerated_insert" parameterClass="MyClass">
> insert sql statement here ....
> </insert>
>
> 2) this is manual code is my attempt to reuse the generated insert
> statement in step 1. But this doesn't work. Is there a way to do this
> correctly?
> <insert id="insert_withReturnId" parameterClass="MyClass">
> <include refid="abatorgenerated_insert" /> <<-- THIS DOESN'T WORK
> <selectKey resultClass="int" keyProperty="Id" type="post">
> SELECT LAST_INSERT_ID()
> </selectKey>
> </insert>
>
>