title: How to perform batch update in Spring with a list of maps?
body: <p>New to Spring, I am trying to insert a <code>List&lt;Map&lt;String, Object&gt;&gt;</code> into a table. Until now I have been using the <code>SqlParameterSource</code> for batch update, which works fine when a java bean is supplied to them. Something like this:</p>
  
  <pre><code>    @Autowired
      private NamedParameterJDBCTemplate v2_template;
  
      public int[] bulkInsertIntoSiteTable(List&lt;SiteBean&gt; list){
              SqlParameterSource[] batch = SqlParameterSourceUtils
                      .createBatch(list.toArray());
              int[] updateCounts = v2_template
                      .batchUpdate(
                              "insert into sitestatus (website, status, createdby) values (:website, :status, :username)",
                              batch);
  
              return updateCounts;
  
          }
  </code></pre>
  
  <p>However, I tried the same technique with a list of maps in place of a bean, it failed (rightly so).</p>
  
  <pre><code>public int[] bulkInsertIntoSiteTable(List&lt;Map&lt;String, Object&gt;&gt; list){
          SqlParameterSource[] batch = SqlParameterSourceUtils
                  .createBatch(list.toArray());
          int[] updateCounts = v2_template
                  .batchUpdate(
                          "insert into sitestatus (website, status, createdby) values (:website, :status, :username)",
                          batch);
  
          return updateCounts;
  
      }
  </code></pre>
  
  <p>The above code failed with the following exception:</p>
  
  <pre><code>Exception in thread "main" org.springframework.dao.InvalidDataAccessApiUsageException: No value supplied for the SQL parameter 'website': Invalid property 'website' of bean class [org.springframework.util.LinkedCaseInsensitiveMap]: Bean property 'website' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
      at org.springframework.jdbc.core.namedparam.NamedParameterUtils.buildValueArray(NamedParameterUtils.java:322)
      at org.springframework.jdbc.core.namedparam.NamedParameterBatchUpdateUtils$1.setValues(NamedParameterBatchUpdateUtils.java:45)
      at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:893)
      at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:1)
      at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:587)
      at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:615)
      at org.springframework.jdbc.core.JdbcTemplate.batchUpdate(JdbcTemplate.java:884)
      at org.springframework.jdbc.core.namedparam.NamedParameterBatchUpdateUtils.executeBatchUpdateWithNamedParameters(NamedParameterBatchUpdateUtils.java:40)
      at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.batchUpdate(NamedParameterJdbcTemplate.java:303)
      at tester.utitlies.dao.VersionTwoDao.bulkInsertIntoSites(VersionTwoDao.java:21)
      at tester.utitlies.runner.Main.main(Main.java:28)
  </code></pre>
  
  <p>It fails as it considers the list to be a batch of beans, I guess. I cannot find a way to perform a batch update in Spring with <strong>a list of maps</strong> and using <code>NamedParameterJDBCTemplate</code>. Please advice.</p>