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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.5.9
    • Component/s: Other
    • Labels:
      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

            People

            Assignee:
            diego dupin Diego Dupin
            Reporter:
            HuDeanY Andreas Soderer
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: