title: MyBatis inserts one to many relationship
body: <p>I have my very simple one <code>(Question)</code> to many <code>(Options)</code> relationship, Option has the FK <code>(questionId)</code> to Question, now I'm going to insert a Question object with a list of Options inside within one XML configuration.</p>
  
  <p>Question:</p>
  
  <pre><code>public Class Question{
      ...
      private Integer questionId;
      private List&lt;Option&gt; options;
      ....
  }
  </code></pre>
  
  <p>Option:</p>
  
  <pre><code>public Class Option{
     ...
     private Integer optionId;
     private String context;
  
     private Integer questionId; //FK
  
     ....
  }
  </code></pre>
  
  <p>The configuration:</p>
  
  <pre><code>...
  
  &lt;insert id="insertQuestion" parameterType="com.pojos.Question" useGeneratedKeys="true"&gt;
  
          INSERT into question (...) VALUES (...);
  
          &lt;selectKey keyColumn="questionId" keyProperty="questionId" resultType="int"&gt;
              SELECT MAX(questionId) FROM question;
          &lt;/selectKey&gt;
  
          INSERT INTO option (context, questionId)
          VALUES
              &lt;foreach collection="options" item="option" open="(" separator="),(" close=")"&gt;
                  #{option.context}, #{questionId}
              &lt;/foreach&gt;
      &lt;/insert&gt;
  
  ...
  </code></pre>
  
  <p>As you can see, I'd like to use the just auto-generated <code>questionId</code> as the FK info for the options, however it doesn't work through, how can I make it work? or I cannot put them into a single  scope? </p>