title: MyBatis dynamic ResultMap. How to return list of different POJO objects?
body: <p>MyBatis mapping issue.</p>
  
  <p>Suppose we have a table USERS</p>
  
  <pre><code>CREATE TABLE USERS(
     USER_ID int(10) NOT NULL AUTO_INCREMENT,
     LOGIN varchar(100) NOT NULL,
     EMAIL varchar(255),
     SALARY int(10),
     AVG_SCORE int(10),
     PRIMARY KEY ( USER_ID )
  );
  </code></pre>
  
  <p>And there are 3 POJO classes - </p>
  
  <pre><code>public class User {
      private Long id;
      private String login;
      private String email;
  
  ...getters/setters
  }
  </code></pre>
  
  <p>and two more classes extending User</p>
  
  <pre><code>public class Student extends User {
      private Integer score;
  ...getters/setters
  }
  
  public class Teacher extends User {
      private Integer salary;
  ...getters/setters
  }
  </code></pre>
  
  <p>and a mapper (I use XML but actually it does not matter).</p>
  
  <pre><code>&lt;select id="selectAll" resultMap="&lt;dynamicResultMapHere&gt;"&gt;
      SELECT * FROM USERS
      &lt;some conditions here&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>I would like to get <code>List&lt;Teacher&gt;</code> or <code>List&lt;Student&gt;</code> instances depending on whether SALARY column is empty or not.</p>
  
  <p>How to add the dynamic results filling?</p>
  
  <p>Actually the case is more complicated. I somehow need to return different results depending on query parameters.</p>