mybatis/mybatis-3 · error · ResultMapException

Error attempting to get column '" + columnName + "' from res

Error message

Error attempting to get column '" + columnName + "' from result set.  Cause: " + e

What it means

BaseTypeHandler.getResult(rs, columnName) wraps every exception thrown while reading a column from the ResultSet via getNullableResult. The failure is either the driver reporting 'column not found' (SQL alias / resultMap mismatch) or a type conversion failure inside the concrete handler.

Source

Thrown at src/main/java/org/apache/ibatis/type/BaseTypeHandler.java:87

            + "Cause: " + e, e);
      }
    } else {
      try {
        setNonNullParameter(ps, i, parameter, jdbcType);
      } catch (Exception e) {
        throw new TypeException("Error setting non null for parameter #" + i + " with JdbcType " + jdbcType + " . "
            + "Try setting a different JdbcType for this parameter or a different configuration property. " + "Cause: "
            + e, e);
      }
    }
  }

  @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);

View on GitHub (pinned to 008069adb1)

Solutions

  1. Match the resultMap column attribute to the exact column label the query returns (add an SQL alias if needed)
  2. Check the Cause for a 'column not found' vs conversion error and fix the query or the property type accordingly
  3. For Oracle unquoted identifiers, use the upper-cased column name in the resultMap

Example fix

// before
SELECT name AS userName ...  <result column="name" property="userName"/>

// after
SELECT name AS userName ...  <result column="userName" property="userName"/>
Defensive patterns

Strategy: try-catch

Validate before calling

// verify expected columns exist before mapping
ResultSetMetaData md = rs.getMetaData();
Set<String> cols = new HashSet<>();
for (int i = 1; i <= md.getColumnCount(); i++) cols.add(md.getColumnLabel(i).toUpperCase());
if (!cols.contains("USERNAME")) throw new IllegalStateException("column USERNAME missing");

Try / catch

try { ... } catch (ResultMapException e) { // e names the column; compare with the SELECT's aliases and fix the resultMap }

Prevention

When it happens

Trigger: A resultMap or auto-mapping references a column name that the SELECT does not return (missing alias, typo, column removed from query); or the handler mapped for the property cannot convert the column value (e.g. reading a non-numeric string as Integer).

Common situations: Changing the SELECT list without updating the resultMap; DB views/queries whose column casing differs (Oracle upper-cases unquoted identifiers); handler mismatch after changing a property type.

Related errors


AI-assisted analysis of mybatis/mybatis-3@008069adb1 (2026-08-14). Data as JSON: /api/errors/b24ed27fc89c215c. Report an issue: GitHub.