Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-285

Statement.getGeneratedKeys() is capping to short on 1.4 series

    XMLWordPrintable

Details

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

      Attachments

        Activity

          People

            diego dupin Diego Dupin
            davidd David Delbecq
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.