[CONJ-285] Statement.getGeneratedKeys() is capping to short on 1.4 series Created: 2016-04-22  Updated: 2016-04-22  Resolved: 2016-04-22

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 1.4.0, 1.4.1, 1.4.2
Fix Version/s: 1.4.3

Type: Bug Priority: Major
Reporter: David Delbecq Assignee: Diego Dupin
Resolution: Duplicate Votes: 0
Labels: None
Environment:

Client: Linux, jdk 1.8.0_31
Server: both mysql and mariadb tested



 Description   

If you use mariadb connector/j on an hibernate application using auto_increment primary key at server side and the value generated is bigger then 32767, the value returned to hibernate during call to getGeneratedKeys() is negative.

Here is a pure jdbc sample code demonstrating the issue:

   Connection connection = DriverManager.getConnection("jdbc:mariadb://localhost/testAutoincrement?user=stress&password=stress");
    connection.setAutoCommit(false);
    PreparedStatement stmt = connection.prepareStatement("insert into GlobalImpl values()", Statement.RETURN_GENERATED_KEYS);
    int updated = stmt.executeUpdate();
    System.out.println("updated " + updated);
    ResultSet rs = stmt.getGeneratedKeys();
    rs.next();
    System.out.println("generated keys count: " + rs.getMetaData().getColumnCount());
    System.out.println("generated keys type: " + rs.getMetaData().getColumnTypeName(1));
    System.out.println("last id -> " + rs.getBigDecimal(1).setScale(0, BigDecimal.ROUND_UNNECESSARY).toBigInteger());
    System.exit(1);

Generated output:

udpdated 1
generated keys count: 1
generated keys type: BIGINT
last id -> -22385

SQL creation script:

CREATE TABLE `GlobalImpl` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=43153 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

If a just change the driver version to 1.3.7, it successfully output the correct value:

updated 1
generated keys count: 1
generated keys type: BIGINT
last id -> 43156

This make the 1.4 driver series just unusable in this case with hibernate



 Comments   
Comment by David Delbecq [ 2016-04-22 ]

Actually the same as issue CONJ-284, can close this one. Sorry about duplicate.

Comment by Diego Dupin [ 2016-04-22 ]

OK, corrective version 1.4.3 is to be released within the hour due to this bug (but may be available only tomorrow in maven due to replication to maven central).

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