title: How to implement one-to-many relationships in Ibatis?
body: <p>Let's say I have this Class:</p>
  
  <pre><code>
      Class A {
          int id;
          int[] b;
          // Other properties
      }
  
      Class B {
          int id;
          // Other properties
      }
  </code></pre>
  
  <p>The Class A has one-to-many relation with class B. I already have a service which caches B objects and return them on id.</p>
  
  <p>Table schema looks something like this</p>
  
  <pre><code>
      Table a:
      -------
        int id,
        prop1,
        etc
  
      Table a_to_b_map
      ----------------
        int a_id,
        int b_id
  
  </code></pre>
  
  <p>Now, how do I map this in iBatis?</p>
  
  <p>Since, B objects are already cached, I want to get the list of ids into A objects and then use the service to enrich As.</p>
  
  <p>Can someone suggest how to go about it?</p>
  
  <p>Two possible alternative I can think of are:</p>
  
  <ol>
  <li>Create an inner class in A (AtoB map) and use a select query in iBatis config to populate this</li>
  <li>Inside the iBatis resultMap/select use another select to get the list of B ids (not too sure on how to do this in config)</li>
  </ol>