| Bug #111530 | useGeneratedKeys bug When using on duplicate key update clause | ||
|---|---|---|---|
| Submitted: | 22 Jun 2023 8:42 | Modified: | 22 Jun 2023 13:31 |
| Reporter: | sungyun kim | Email Updates: | |
| Status: | Not a Bug | Impact on me: | |
| Category: | Connector / J | Severity: | S3 (Non-critical) |
| Version: | 8.0.29 | OS: | Any |
| Assigned to: | CPU Architecture: | Any | |
[22 Jun 2023 13:31]
MySQL Verification Team
HI Mr. kim, Thank you for your bug report. You have set the category for your report as "MySQL Server". However, it seems that your bug is related to Connector/J. Hence, please file a new report, with a category of Connector/J. Also, include entire test case, which means all of the code, CREATE TABLE, all rows for the table and so on ........ Not a bug.

Description: I'm using mysql version 8.0.29 and connector/j also 8.0.29 <insert id="upsertPost" useGeneratedKeys="true" keyProperty="id"> INSERT INTO posts( postKey, title, url, type, status, createdAt, updatedAt ) VALUES ( #{postKey}, #{title}, #{url}, #{type}, #{status}, #{createdAt}, #{updatedAt} ) ON DUPLICATE KEY UPDATE updatedAt = #{updatedAt}, title = #{title}, url = #{url} </insert> and I tried to get 'id' value when on update, but sometimes It is null. It's not always reproduced. In the test code below, I could see that the 'id' value is null when repeatedly called several times. (ps. Please understand that the sentence may be awkward because my English is not good) Thank you How to repeat: @Test public void test() { for (int i=0;i<5; i++) { PostModel row = new PostModel(); row.postKey = "post key"; row.title = "title"; row.url = null; row.type = "POST"; row.createdAt = Timestamp.from(Instant.now()) row.updatedAt = Timestamp.from(Instant.now()) mapper.upsertPost(row); System.out.println(i + ": id " + row.id); } }