resultMap can not mapping <result column="d.id" property="id"/> when the field "fullColumnNameToIndex" contains “d.id”
See original GitHub issueMyBatis version
3.5.5
Database vendor and version
mysql 8.0
Test case or example project
as follow,resultMap has result column = d.id Mapping sysDepartment.Id
<resultMap id="listMap" type="SysUser ">
<result column="u.id" property="id"/>
<result column="DepartmentId" property="departmentId"/>
<association property="sysDepartment" javaType="SysDepartment">
<result column="d.id" property="id"/>
</ association>
</ resultMap>
<select id="list" resultMap="listMap">
select u.* ,d.* from SysUser u left join SysDepartment d on d.Id = u.departmentId
</select>
as follow,in source code class DefaultColumnDefinition, the fullColumnNameToIndex field contains d.id column.so Under normal conditions, column = d.id can Mapping sysDepartment.Id.
as follow,in class method DefaultResultSetHandler.createRowKeyForMappedProperties,because mappedColumnNames not contains d.id,so code final Object value = th.getResult(rsw.getResultSet(), column) can not excute. this cause column = d.id can not Mapping sysDepartment.Id.
Expected result
resultMap has result **column = d.id column = d.id can Mapping sysDepartment.Id
Actual result
resultMap has result **column = d.id column = d.id can not Mapping sysDepartment.Id
##how to fix DefaultResultSetHandler(class).createRowKeyForMappedProperties(method).mappedColumnNames(field) cotains d.id column just like DefaultColumnDefinition(class).findColumn(method).columnToIndexCache(field)
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
but in the source code, class DefaultColumnDefinition.findColumn.fullColumnNameToIndex(used to mapping result set.) contains table names i.e. both u.id and d.id column, if the source code DefaultResultSetHandler(class).createRowKeyForMappedProperties(method).mappedColumnNames (field) also contains d.id and u.id, Column labels will be able include table names i.e. both u.id and d.id . I tried and successfully
I did quick test. A few drivers (mysql, mariadb, pgjdbc) support it, but others (e.g. mssql, oracle, h2, hsqldb) don’t. Closing.