ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tony Qian" <daqiqi...@aol.com>
Subject selectKey Question for MySql
Date Tue, 18 Apr 2006 21:41:55 GMT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title></title>
</head>
<body>
<font size="2"><font face="Arial,sans-serif">All,<br>
<br>
I have a transaction which requires to insert an user to member table.
The primary key of the member table is member_id which is automatically
incremented. name column is UNIQUE. </font></font><font size="2"  face="Arial,sans-serif"><font
face="Arial,sans-serif">I need to return
the memberId for insert transaction.</font></font><font size="2"><font
 face="Arial,sans-serif"> If an user tries to insert an entry with a
name which is already in the table, I need to do update. Here is iBATIS
map I have:<br>
<br>
&lt;insert id="abatorgenerated_insert" parameterClass="Member"&gt;<br>
&nbsp;INSERT INTO member (member_id, name)<br>
&nbsp;&nbsp;&nbsp; VALUES (#memberId:BIGINT#, #name:VARCHAR#,)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;selectKey resultClass="java.lang.Long"
keyProperty="memberId"&gt;&nbsp;&nbsp;<font color="#0000ff"> // manually
added</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
SELECT LAST_INSERT_ID() AS memberId<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/selectKey&gt;<br>
&nbsp;ON DUPLICATE KEY UPDATE<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; member_id=#memberId:BIGINT#,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name = #name:VARCHAR#<br>
&lt;/insert&gt;<br>
<br>
insert and update were done correctly. The problem I have is that
memberId of Member is set to 0 when ON DUPLICATE KEY UPDATE is executed.<br>
Any suggestion to fix it?<br>
<br>
Thanks,<br>
Tony<br>
</font></font>
</body>
</html>


Mime
View raw message