ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Marshall" <ch...@campsbayterrace.com>
Subject Re: iBATIS insert does not execute
Date Fri, 18 Apr 2008 14:36:20 GMT
Thanks for your reply Axel

I think that the problem is related to passing a null primary key in
the insert statement when the key is autogenerated (by MySQL).
What is the best practice here?  I have tried the following MySQL
specific SqlMap snippet with success, but was hoping for a solution
portable among databases:

 <insert id="insert" parameterClass="net.mycompany.Role">

         <selectKey resultClass="java.lang.Integer" keyProperty="roleid">
               select LAST_INSERT_ID() AS value
         </selectKey>

   insert into role (RoleID, ParentID, Name, Notes)
   values (#roleid:INTEGER#, #parentid:INTEGER#, #name:VARCHAR#,
#notes:VARCHAR#)
 </insert>


Thanks Chris



On 18/04/2008, Leucht, Axel <Axel.Leucht@prodv.de> wrote:
> Can you describe the database table structure you're working on?
>
> /Axel
>
>
> >>-----Urspr√ľngliche Nachricht-----
> >>Von: Chris Marshall [mailto:chris@campsbayterrace.com]
> >>Gesendet: Freitag, 18. April 2008 16:02
> >>An: user-java@ibatis.apache.org
> >>Betreff: Re: iBATIS insert does not execute
> >>

Mime
View raw message