[CONJ-1117] batch insert can not get all GeneratedKeys Created: 2023-10-27 Updated: 2023-12-14 Resolved: 2023-12-14 |
|
| Status: | Closed |
| Project: | MariaDB Connector/J |
| Component/s: | batch |
| Affects Version/s: | 3.2.0, 3.1.4 |
| Fix Version/s: | 3.3.2 |
| Type: | Bug | Priority: | Critical |
| Reporter: | hsin | Assignee: | Diego Dupin |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | generated, key | ||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Description |
|
org.mariadb.jdbc.Statement#getGeneratedKeys can not get allinsertIds |
| Comments |
| Comment by hsin [ 2023-10-27 ] | ||||||||||||||||||||||
|
org.mariadb.jdbc.message.server.OkPacket#getAffectedRows | ||||||||||||||||||||||
| Comment by Diego Dupin [ 2023-10-27 ] | ||||||||||||||||||||||
|
MySQL/MariaDB protocol doesn't permit to know that. Only the first insert id value is known. Knowing @@auto_increment_increment :
of more simply since MariaDB 10.5.0, using RETURNING value :
| ||||||||||||||||||||||
| Comment by hsin [ 2023-11-09 ] | ||||||||||||||||||||||
|
the same sql but have two result betwen 2.7.9 and 3.2.0 | ||||||||||||||||||||||
| Comment by hsin [ 2023-11-10 ] | ||||||||||||||||||||||
|
@Diego Dupin | ||||||||||||||||||||||
| Comment by Diego Dupin [ 2023-11-16 ] | ||||||||||||||||||||||
|
This is still an error in 2.x to return multiple id's in that case. Mysql connector will return one value as well. | ||||||||||||||||||||||
| Comment by hsin [ 2023-11-27 ] | ||||||||||||||||||||||
|
But MyBatis requires multiple IDs to be returned in <org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator#processBatch>.It was normal to use this in 2.x, but now there is an exception when upgrading to 3.x | ||||||||||||||||||||||
| Comment by Diego Dupin [ 2023-12-05 ] | ||||||||||||||||||||||
|
Since breaking MyBatis, a solution can be done to add a compatibility option to have the same behavior than 2.x | ||||||||||||||||||||||
| Comment by Diego Dupin [ 2023-12-14 ] | ||||||||||||||||||||||
|
new option `returnMultiValuesGeneratedIds` added for connector 2.x compatibility. When enable, getGeneratedKeys() will return all ids of multi-value inserts. |