mybatis/mybatis-3 · error · ResultMapException
Error attempting to get column #" + columnIndex + " from res
Error message
Error attempting to get column #" + columnIndex + " from result set. Cause: " + e
What it means
Identical wrapper to the by-name variant, but the read was made by column index: getNullableResult(rs, columnIndex) threw and MyBatis reports which positional column (#1, #2, ...) failed. Index-based access is used by constructor auto-mapping and by results mapped without explicit column names.
Source
Thrown at src/main/java/org/apache/ibatis/type/BaseTypeHandler.java:97
}
}
@Override
public T getResult(ResultSet rs, String columnName) throws SQLException {
try {
return getNullableResult(rs, columnName);
} catch (Exception e) {
throw new ResultMapException("Error attempting to get column '" + columnName + "' from result set. Cause: " + e,
e);
}
}
@Override
public T getResult(ResultSet rs, int columnIndex) throws SQLException {
try {
return getNullableResult(rs, columnIndex);
} catch (Exception e) {
throw new ResultMapException("Error attempting to get column #" + columnIndex + " from result set. Cause: " + e,
e);
}
}
@Override
public T getResult(CallableStatement cs, int columnIndex) throws SQLException {
try {
return getNullableResult(cs, columnIndex);
} catch (Exception e) {
throw new ResultMapException(
"Error attempting to get column #" + columnIndex + " from callable statement. Cause: " + e, e);
}
}
public abstract void setNonNullParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType)
throws SQLException;
/**View on GitHub (pinned to 008069adb1)
Solutions
- Use the reported index to identify which column in the SELECT failed, then check its value against the property's handler
- Prefer explicit column names in the resultMap (or column aliases) instead of positional coupling
- If constructor auto-mapping is used, annotate the constructor with @Param and keep the query in sync
Example fix
// before SELECT id, email, name ... matched to constructor (Long, String) // positional drift // after SELECT id, name, email ... with explicit @Param ordering in the constructor
Defensive patterns
Strategy: try-catch
Try / catch
try { ... } catch (ResultMapException e) { // message shows the 1-based index; map it back to the SELECT column order and fix ordering or handler } Prevention
- Prefer name-based resultMap entries over positional coupling
- When using constructor auto-mapping, keep @Param-annotated constructor order aligned with the query
- Review column order changes in shared SELECT fragments
When it happens
Trigger: Constructor-based auto-mapping where the SELECT column order no longer matches the constructor argument order; an aggregate query whose column positions shifted; a handler that fails converting the value at that position.
Common situations: Reordering columns in a shared SELECT; adding/removing a column while relying on positional mapping; resultMap using column indexes after a query refactor.
Related errors
- Constructor auto-mapping of ''{0}'' failed. The constructor
- Unknown column is detected on '" + mappedStatement.getId() +
- Error attempting to get column '" + columnName + "' from res
- Unknown execution method for: {name}
- Mapper method '{name}' attempted to return null from a metho
AI-assisted analysis of mybatis/mybatis-3@008069adb1 (2026-08-14).
Data as JSON: /api/errors/3209c26125d99b18.
Report an issue: GitHub.