Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Duplicate
-
1.4.0, 1.4.1, 1.4.2
-
None
-
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