title: Multiple one-to-many relations in Spring JDBC
body: <p>I am using Spring JDBC and I am a bit unsure on how to work with multiple one-to-many relations (or many-to-many). In this case I am injecting a repository into one of my resultsetextractors so that I can retrieve its associations. Is this the way to do it? Is it bad? Are there other better ways?</p>
  
  <p><em>Note: I have left out the injection of repository</em></p>
  
  <pre><code>public class SomeResultSetExtractor implements ResultSetExtractor {
  
    public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
      List result = new LinkedList();
  
      while (rs.next()) {
          SomeObject object = new SomeObject(rs.getString(1), rs.getLong(2));
          result.add(object);
  
          List&lt;AnotherObject&gt; otherObjects = anotherRepository.findAllById(object.getId);
          object.setOtherObjects(otherObjects);
          // and so on
      }
  
      return result;
  
    }
  }
  </code></pre>
  
  <p>Okey so after reading Dmytro Polivenok answer I have changed to RowMapper interface instead and I am currently using the other repositories to populate all associations  like I show in my example. Is this a good way of doing it? </p>