title: Inserting child objects in MyBatis
body: <p>I have a very simple object graph that I want to store in a database using MyBatis.  If I make a brand new object graph (a BatisNode with two details), how do I write code to be sure the child objects are created?  Here are the details:</p>
  
  <pre>
  <code>
  public class BatisNode {
      protected int id;
      protected List details;
      protected String name;
          //Constructor and getters.
  }
  
  public class BatisNodeDetail {
      protected int id;
      protected BatisNode parent;
      protected String name;
          //Constructor and getters.
  }
  </code>
  </pre>
  
  <p>Schema:</p>
  
  <pre>
  CREATE TABLE node (
      node_id int auto_increment primary key,
      name varchar(255)
  );
  
  CREATE TABLE node_detail(
      node_detail_id int auto_increment primary key,
      name varchar(255)
  );
  </pre>
  
  <p>Mapper:</p>
  
  <pre>
      
          
  INSERT INTO node (
    name
  )
  SELECT #{name};
          
  
          
  SELECT node_id id,
  name
  FROM node
  WHERE node_id=#{id};
          
  
          
          
  
  
  </pre>