Bug #111674 getGeneratedKeys returns BigInteger, instead of long
Submitted: 6 Jul 2023 7:48 Modified: 6 Jul 2023 8:15
Reporter: Youichi Aramaki Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:6.0.1 and newer OS:Any
Assigned to: CPU Architecture:Any

[6 Jul 2023 7:48] Youichi Aramaki
Description:
getGeneratedKeys in MySQL Connector/J 6.0.1 and newer version returns BigInteger, instead of Long in older version.

As version 5.xx returns a generated key as Long, this change causes applications using getGeneratedKeys when retrieving a value by getObject.

This change has been introduced in the below commit(change type from Types.BIGINT to MysqlType.BIGINT_UNSIGNED), but I could not understand the reason.
https://github.com/mysql/mysql-connector-j/commit/e7925417c97a8861c73be023f6ddec25bde67914...

How to repeat:
    public void testInsertWithGeneratedKeys() throws SQLException, InterruptedException {
        final Connection connection = DriverManager.getConnection("jdbc:mysql://xxxxxxx", "xxxx", "xxxxxx");
        System.out.println(connection.getMetaData().getDriverMajorVersion());
        Statement statement = connection.createStatement();
        statement.executeUpdate("INSERT INTO test(name) VALUES(1)", Statement.RETURN_GENERATED_KEYS);
        ResultSet generatedKeys = statement.getGeneratedKeys();
        while (generatedKeys.next()) {
            System.out.println(generatedKeys.getObject(1) + " " + generatedKeys.getObject(1).getClass());
        }
    }
-> In 6.0.1 and newer version returns a generated key as BigInteger, in 6.0.0 and older version returns a generated key as Long.
[6 Jul 2023 7:58] Youichi Aramaki
Sample DDL looks like this.
CREATE TABLE test(test_id bigint auto_increment, name int, primary key(test_id));
[6 Jul 2023 8:15] MySQL Verification Team
Hello Youichi Aramaki,

Thank you for the report and feedback.
IMHO this is duplicate of Bug #101823, please see Bug #101823.

regards,
Umesh