title: association in mybatis
body: <p>I meet some problems in mybatis. This is my configuration:</p>
  
  <p>PostMapper.xml</p>
  
  <pre><code>&lt;mapper namespace="com.king.model.PostMapper"&gt;
      &lt;select id="selectById" parameterType="int" resultMap="postMap"&gt;
          select * from posts where id = #{id}
      &lt;/select&gt;
      &lt;select id="selectAll" resultType="hashmap"&gt;
          select * from posts order by created_at desc
      &lt;/select&gt;
  
      &lt;resultMap id="postMap" type="Post"&gt;
          &lt;result property="createDate" column="created_at" /&gt;
          &lt;result property="updateDate" column="updated_at" /&gt;
      &lt;/resultMap&gt;
  &lt;/mapper&gt;
  </code></pre>
  
  <p>CommentMapper.xml</p>
  
  <pre><code>&lt;mapper namespace="com.king.model.CommentMapper"&gt;
      &lt;select id="selectById" parameterType="int" resultMap="commentMap"&gt;
          select * from comments where id = #{id} order by id desc
      &lt;/select&gt;
      &lt;select id="selectAll" resultMap="commentMap"&gt;
          select * from comments
      &lt;/select&gt;
      &lt;select id="selectByPost" resultMap="commentMap" parameterType="int"&gt;
          select * from comments where post_id=#{id}
      &lt;/select&gt;
      &lt;resultMap id="commentMap" type="Comment"&gt;
          &lt;result property="createDate" column="created_at" /&gt;
          &lt;result property="updateDate" column="updated_at" /&gt;
          &lt;association property="post" column="post_id" javaType="Post" select="com.king.model.PostMapper.selectById" /&gt;
      &lt;/resultMap&gt;
  &lt;/mapper&gt;
  
  
  public class Post {
      private int id;
      private String title;
      private String body;
      private Date createDate;
      private Date updateDate;
      private List&lt;Comment&gt; comments;
  }
  
  public class Comment {
      private int id;
      private String commenter;
      private String body;
      private Post post;
      private Date createDate;
      private Date updateDate;
  }
  </code></pre>
  
  <p>In CommentDao:</p>
  
  <pre><code>public List&lt;Comment&gt; listForPost(Post post) {
      return getSqlSession().selectList("com.king.model.CommentMapper.selectByPost", post.getId());
  }
  </code></pre>
  
  <p>Then in my controller,I try to list all the comments for one given post:</p>
  
  <pre><code>List&lt;Comment&gt; coms = commentDao.listForPost(post);
  post.setComments(coms)
  </code></pre>
  
  <p>And I found the above code will trigger two sql select statement:</p>
  
  <pre><code>select * from comments where post_id=? 
  select * from posts where id = ? 
  </code></pre>
  
  <p>However through mybatis 3 guide,it specify that in this suitation, it will cause the "N+1" problem.</p>
  
  <p>For each selected comment,it will trigger select statement for details(the post).</p>
  
  <p>But here is only two select. </p>
  
  <p>What's going on?</p>
  
  <p>And in mybatis should the relation be set as bidirectional or unidirectional for the one-many or many-many association?</p>