All,

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.
I need to return the memberId for insert transaction. 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:

<insert id="abatorgenerated_insert" parameterClass="Member">
 INSERT INTO member (member_id, name)
    VALUES (#memberId:BIGINT#, #name:VARCHAR#,)
      <selectKey resultClass="java.lang.Long" keyProperty="memberId">   // manually added
            SELECT LAST_INSERT_ID() AS memberId
      </selectKey>
 ON DUPLICATE KEY UPDATE
      member_id=#memberId:BIGINT#,
      name = #name:VARCHAR#
</insert>

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.
Any suggestion to fix it?

Thanks,
Tony

Reply via email to