title: Spring Batch: How to Insert multiple key-value pairs into Database table for each item
body: <p>After processing some XML files with Spring Batch ItemProcessor.
  The ItemProcessor returns items like this:</p>
  
  <pre><code>MetsModsDef
  {
     int id;
     String title;
     String path;
     Properties identifers;
     ....
  }
  </code></pre>
  
  <p>now  i need to save  this items into a database, so that the
     (id, title, path) will go into the "Work" table</p>
  
  <p>and all the Properties stored in the  "identifiers" field go into a "Key/Value"-Table called "Identifier" (work, identitytype, identityValue)</p>
  
  <p>how can i acheive this?</p>
  
  <p>currently i am using a CompositeItemWriter  to split the object and write it into two tables like this:</p>
  
  <pre><code>   public ItemWriter&lt;MetsModsDef&gt; MultiTableJdbcWriter(@Qualifier("dataSource") DataSource dataSource) {
  
      CompositeItemWriter&lt;MetsModsDef&gt; cWriter = new CompositeItemWriter&lt;MetsModsDef&gt;();
  
      JdbcBatchItemWriter hsqlWorkWriter = new JdbcBatchItemWriterBuilder()
          .itemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider&lt;&gt;())
          .sql("INSERT INTO work (id, title, path,enabled) VALUES (:id, :title,:path,1)" )
          .dataSource(dataSource)
          .build();
  
      JdbcBatchItemWriter hsqlIdentifierWriter = new JdbcBatchItemWriterBuilder()
          .itemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider&lt;&gt;())
          .sql("INSERT INTO identity (work, identitytype, identityValue) VALUES (:work, :identitytype, :identityValue)" )
          .dataSource(dataSource)
          .build();
  
      List&lt;ItemWriter&lt;? super MetsModsDef&gt;&gt; mWriter = new ArrayList&lt;ItemWriter&lt;? super MetsModsDef&gt;&gt;();
      mWriter.add(hsqlWorkWriter);
      mWriter.add(hsqlIdentifierWriter);
      cWriter.setDelegates(mWriter);
  </code></pre>
  
  <p>but this will not work  for a propertylist since (work, identitytype, identityValue)  are not part of my domain object MetModsDef which only contains one map of properties which are supposed to go into the Identifier table.</p>
  
  <p>i have found advice on how to do it when writing to a file, 
  and even on using a splitter pattern from Spring-Integration <a href="https://stackoverflow.com/questions/7894445/read-one-record-item-and-write-multiple-records-items-using-spring-batch">Read one record/item and write multiple records/items using spring batch</a>
  but i am still not sure how to actually do it, when writing out via jdbc or hibernate (which i assume would be similarish )
  thanks for your advice !</p>