Bug #42309 Statement.getGeneratedKeys() returns 2 keys when using ON DUPLICATE KEY UPDATE
Submitted: 23 Jan 2009 18:17 Modified: 28 Jan 2009 11:41
Reporter: Jess Balint Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1 OS:Any
Assigned to: Jess Balint CPU Architecture:Any
Tags: ON DUPLICATE KEY UPDATE

[23 Jan 2009 18:17] Jess Balint
Description:
Statement.getGeneratedKeys() returns 2 keys when using ON DUPLICATE KEY UPDATE and the row is updated, not inserted.

This is fixed for the following cases:

Statement & PreparedStatement:
plain insert
batch insert (rewritten & not-rewritten)

The updated count will still be 2 for each row, as defined by MySQL server:
http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html
  " With ON DUPLICATE KEY UPDATE, the affected-rows value per row is 1 if the row is inserted as a new row and 2 if an existing row is updated. "

How to repeat:
.

Suggested fix:
Return only one row per generated key.
[23 Jan 2009 18:17] Jess Balint
Fix will be included in 5.1.7.
[28 Jan 2009 11:41] Tony Bedford
An entry was added to the 5.1.7 changelog:

Statement.getGeneratedKeys() returned two keys when using ON DUPLICATE KEY UPDATE and the row was updated, not inserted.