GeneratedKeyHolder.getKey() should accept on-duplicate-key result on MySQL [SPR-17283] #21816
Labels
in: data
Issues in data modules (jdbc, orm, oxm, tx)
status: declined
A suggestion or change that we don't feel we should currently apply
type: enhancement
A general enhancement
member sound opened SPR-17283 and commented
There is an issue in
spring-jdbc
since 2015:Root cause seems to be using
mysql
withON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id)
;If the database row already exists, some columns should only be updated and the correct id of the column should be returned, without an extra SELECT. Therefore the
LAST_INSERT_UD
function is used.Problem, as described in the question: "The keyholder is assuming two rows have been modified (even though only one has been) and is incorrectly returning the ID plus the next sequential ID (i.e. the ID plus 1)."
You can reproduce it by creating initial data in mysql, and updating that data as follows:
Exception:
Affects: 5.0.9
Reference URL: https://stackoverflow.com/questions/30107388/mysql-on-duplicate-key-update-with-primary-key-and-unique-key
The text was updated successfully, but these errors were encountered: