[CONJ-431] Bulk-Insert in table with autoincrement only returns 1 generated key Created: 2017-02-14  Updated: 2017-03-03  Resolved: 2017-03-03

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: None
Fix Version/s: 1.5.9

Type: Bug Priority: Major
Reporter: Andreas Soderer Assignee: Diego Dupin
Resolution: Fixed Votes: 1
Labels: None


 Description   

Hello MariaDB,
Seems like I found a bug in your current MariaDB JDBC connector (Version 1.5.7).
When using the following Java code to bulk insert data in our MariaDB via JDBC/Spring-JDBC the attached "org.springframework.jdbc.support.GeneratedKeyHolder.GeneratedKeyHolder" returns only 1 generated key, even though there have been generated more than 1 within the DB, which can be verified in the DB.
The MySQL JDBC connector (Version 5.1.40) is working fine and returns the correct number of generated keys.

If you need some more data on this error, please contact me.

with kind regards
Anndreas Soderer
AGNITAS AG

JAVA-Code:

JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource());
 
KeyHolder keyHolder = new GeneratedKeyHolder();
final String query = queryStringBuilder.toString();
jdbcTemplate.update(
new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement ps =
connection.prepareStatement(query, new String[] {"customer_id"});
return ps;
}
},
keyHolder);
 
List<?> keys = keyHolder.getKeyList();
for (Object key : keys) {
@SuppressWarnings("unchecked")
Map<Object, Object> keyMap = (Map<Object, Object>)key;
Entry<Object, Object> entry = keyMap.entrySet().iterator().next();
Long id = (Long) entry.getValue();
results.add(id.intValue());
}



 Comments   
Comment by Diego Dupin [ 2017-02-14 ]

Hi Andreas ,
Just to be sure, code doesn't show this, Query is a "multi values" query like "INSERT INTO <table> values ('x'), ('y), .... ?

Comment by Andreas Soderer [ 2017-02-15 ]

Exactly.
The SQL-DML-Statement looks like:
INSERT INTO mytable (field1, field2, ...) VALUES
('data11', 'data12'),
('data21', 'data22'),
('data31', 'data32')

The column "customer_id" is the auto_increment primary key of "mytable", which is not part of the SQL-Statement.

Comment by Iwan Schafer [ 2017-02-20 ]

Hi,
I can confirm this issue using version 1.5.8.
Run into it during our check, if we can upgrade from 1.5.4 to 1.5.8.

Comment by Diego Dupin [ 2017-03-03 ]

Will be released with1.5.9 (in a few days)

Generated at Thu Feb 08 03:15:37 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.