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 Mark Volkmann <ma...@ociweb.com> on 2007/02/08 18:36:07 UTC

getting auto-gen key after insert

I used Abator to generate Spring DAOs. When I use the insert method  
of the generated DAOs to insert a new row in a table, how can I get  
the primary key that was assigned to the record when it is set in the  
table definition to auto-generate an integer key?

When I just use iBATIS without Spring DAOs, I can do this

   sqlMap.insert("Artist.insert", artist);

and it populates the Java object artist with the generated key.

However, when I use the Abator generated Spring DAOs and do this

   artistDAO.insert(artist);

it doesn't not populate the Java object artist with the generated key.

Re: getting auto-gen key after insert

Posted by Mark Volkmann <ma...@ociweb.com>.
On Feb 8, 2007, at 12:55 PM, Jeff Butler wrote:

> You need to add a <generatedKey> element to your Abator  
> configuration.  Then Abator will generate the proper <selectKey>  
> element.

Thanks! That fixed it.

> On 2/8/07, Mark Volkmann <ma...@ociweb.com> wrote:
> I used Abator to generate Spring DAOs. When I use the insert method
> of the generated DAOs to insert a new row in a table, how can I get
> the primary key that was assigned to the record when it is set in the
> table definition to auto-generate an integer key?
>
> When I just use iBATIS without Spring DAOs, I can do this
>
>   sqlMap.insert(" Artist.insert", artist);
>
> and it populates the Java object artist with the generated key.
>
> However, when I use the Abator generated Spring DAOs and do this
>
>   artistDAO.insert(artist);
>
> it doesn't not populate the Java object artist with the generated key.
>


Re: getting auto-gen key after insert

Posted by Jeff Butler <je...@gmail.com>.
You need to add a <generatedKey> element to your Abator configuration.  Then
Abator will generate the proper <selectKey> element.

Jeff Butler




On 2/8/07, Mark Volkmann <ma...@ociweb.com> wrote:
>
> I used Abator to generate Spring DAOs. When I use the insert method
> of the generated DAOs to insert a new row in a table, how can I get
> the primary key that was assigned to the record when it is set in the
> table definition to auto-generate an integer key?
>
> When I just use iBATIS without Spring DAOs, I can do this
>
>   sqlMap.insert("Artist.insert", artist);
>
> and it populates the Java object artist with the generated key.
>
> However, when I use the Abator generated Spring DAOs and do this
>
>   artistDAO.insert(artist);
>
> it doesn't not populate the Java object artist with the generated key.
>