title: Cleanly creating an object graph of domain objects using SimpleJdbcTemplate
body: <p>For a new project, we've decided to use Spring MVC, and JdbcTemplate (specifically SimpleJdbcTemplate) for persisting domain objects. One issue I've been having with this approach is how to cleanly create object graphs from SELECT queries. The RowMapper mechanism seems to work great when I am pulling rows from a single table; I become concerned when I'm mapping the results of a JOIN query.</p>
  
  <p>To give a concrete (yet entirely fabricated) example, suppose I have two entities in an N-to-1 relationship:</p>
  
  <pre><code>public class Invoice {
      private Customer customer;
      ...
  }
  
  public class Customer {
      private int id;
      private String name;
      ...
  }
  </code></pre>
  
  <p>I would like to be able to call a <code>selectInvoices()</code> method on my <code>InvoiceDAO</code>, and retrieve a list of <code>Invoice</code>'s populated with fully-formed <code>Customer</code> instances. Instead, I find myself tempted to do something like the following:</p>
  
  <pre><code>public class Invoice {
      // this makes me unhappy
      private int customerId;
      ...
  }
  </code></pre>
  
  <p>What is the best practice for cleanly making this happen? Should I just bite the bullet and use an ORM?</p>