I have done a lot of research and no avail. In Mybatis documentation, it says
id – an ID result; flagging results as ID will help improve overall performance
result – a normal result injected into a field or JavaBean property
If they can both inject into a field, and id has performance improvement, so what stops me from only using id at all? Is this just semantic that I will map the primary key to id tag?
I have tried:
<resultMap id="teacherMap" type="me.funmap.model.Teacher" autoMapping="true">
<result column="t_id" property="t_id"/>
<collection property="students" javaType="List" ofType="me.funmap.model.Student" autoMapping="true">
<result column="s_id" property="s_id"/>
</collection>
</resultMap>
and
<resultMap id="teacherMap" type="me.funmap.model.Teacher" autoMapping="true">
<id column="t_id" property="t_id"/>
<collection property="students" javaType="List" ofType="me.funmap.model.Student" autoMapping="true">
<id column="s_id" property="s_id"/>
</collection>
</resultMap>
the statement
<select id="getAllTeacher" resultMap="teacherMap">
SELECT teacher.t_id, t_name, s_id from teacher INNER JOIN student ON teacher.t_id = student.t_id
</select>
result of statement
t_id t_name s_id
| 1 | teacher | 38 |
| 1 | teacher | 39 |
| 1 | teacher | 40 |
| 1 | teacher | 41 |
| 1 | teacher | 42 |
| 1 | teacher | 43 |
I get the same result using either id or result, so what is the difference between <result>
and <id>
tag in resultMap?