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

Bulk-Insert in table with autoincrement only returns 1 generated key

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • None
    • 1.5.9
    • Other
    • 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());
      }
      

      Attachments

        Activity

          diego dupin Diego Dupin added a comment - - edited

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

          diego dupin Diego Dupin added a comment - - edited Hi Andreas , Just to be sure, code doesn't show this, Query is a "multi values" query like "INSERT INTO <table> values ('x'), ('y), .... ?
          HuDeanY Andreas Soderer added a comment - - edited

          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.

          HuDeanY Andreas Soderer added a comment - - edited 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.
          ischafer Iwan Schafer added a comment -

          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.

          ischafer Iwan Schafer added a comment - 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.
          diego dupin Diego Dupin added a comment -

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

          diego dupin Diego Dupin added a comment - Will be released with1.5.9 (in a few days)

          People

            diego dupin Diego Dupin
            HuDeanY Andreas Soderer
            Votes:
            1 Vote for this issue
            Watchers:
            4 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.