mybatis/mybatis-3 · error · TypeException

Could not set parameters for mapping: " + parameterMapping +

Error message

Could not set parameters for mapping: " + parameterMapping + ". Cause: " + e

What it means

After a TypeHandler is chosen, DefaultParameterHandler calls typeHandler.setParameter(ps, i+1, value, jdbcType) to bind the value. Any TypeException or SQLException thrown during binding is re-thrown as a TypeException that includes the full parameterMapping and the original cause. The root cause is usually a driver-level conversion failure or a handler bug — the mapping text tells you which parameter to look at.

Source

Thrown at src/main/java/org/apache/ibatis/scripting/defaults/DefaultParameterHandler.java:176

              typeHandler = ObjectTypeHandler.INSTANCE;
            }
          } else if (typeHandler == null) {
            if (propertyGenericType == null) {
              propertyGenericType = value.getClass();
            }
            typeHandler = typeHandlerRegistry.getTypeHandler(propertyGenericType, actualJdbcType, null);
          }
          if (typeHandler == null) {
            typeHandler = typeHandlerRegistry.getTypeHandler(actualJdbcType);
          }
          if (typeHandler == null) {
            throw new TypeException("Could not find type handler for Java type '" + propertyGenericType.getTypeName()
                + "' nor JDBC type '" + actualJdbcType + "'");
          }
          try {
            typeHandler.setParameter(ps, i + 1, value, jdbcType);
          } catch (TypeException | SQLException e) {
            throw new TypeException("Could not set parameters for mapping: " + parameterMapping + ". Cause: " + e, e);
          }
        }
      }
    }
  }

  private MetaObject getParamMetaObject() {
    if (paramMetaObject != null) {
      return paramMetaObject;
    }
    paramMetaObject = configuration.newMetaObject(parameterObject);
    return paramMetaObject;
  }

  private JdbcType getParamJdbcType(PreparedStatement ps, int paramIndex) {
    try {
      if (paramMetaData == null) {
        paramMetaData = ps.getParameterMetaData();

View on GitHub (pinned to 008069adb1)

Solutions

  1. Read the nested Cause: fix the data/conversion problem it names (truncate strings, fix column sizes, convert value types before passing)
  2. For null parameters add jdbcType: #{field,jdbcType=VARCHAR}
  3. Debug/fix custom TypeHandler.setParameter to handle the failing value
  4. Align the bean field type and jdbcType with the actual column type in the DB

Example fix

<!-- before -->
#{remark}  <!-- null remark on Oracle -> driver error -->

<!-- after -->
#{remark,jdbcType=VARCHAR}
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-validate value sizes/conversions before executing, e.g.
if (value instanceof String s && s.length() > COLUMN_SIZE) {
  throw new IllegalArgumentException("Value too long for column");
}

Try / catch

try {
  session.update("updateStmt", params);
} catch (PersistenceException e) {
  Throwable cause = e.getCause();
  if (cause instanceof TypeException && cause.getMessage().contains("Could not set parameters for mapping")) {
    // inspect parameterMapping in the message; fix value/jdbcType, then surface a clear error
  } else throw e;
}

Prevention

When it happens

Trigger: Sending a String too long for VARCHAR(n); a value the JDBC driver cannot convert (e.g. serializing an object to a BLOB that the driver rejects); a custom TypeHandler whose setNonNullParameter throws; charset/locale conversion errors; assigning null with a driver that needs a concrete jdbcType.

Common situations: DB schema changes (shorter columns, different types) after mappers were written; driver-version-specific conversion bugs; custom TypeHandlers not handling all value states; forgetting jdbcType for nullable parameters on Oracle.

Related errors


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