mybatis/mybatis-3 · error · TypeException
Error setting non null for parameter #" + i + " with JdbcTyp
Error message
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
What it means
The parameter was non-null and MyBatis dispatched it to the type handler's setNonNullParameter, but that call threw (driver conversion error, data truncation, wrong handler for the value's real type). This TypeException is a wrapper: the actionable detail is always in the caused-by chain.
Source
Thrown at src/main/java/org/apache/ibatis/type/BaseTypeHandler.java:75
@Override
public void setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException {
if (parameter == null) {
if (jdbcType == null) {
throw new TypeException("JDBC requires that the JdbcType must be specified for all nullable parameters.");
}
try {
ps.setNull(i, jdbcType.TYPE_CODE);
} catch (SQLException e) {
throw new TypeException("Error setting null for parameter #" + i + " with JdbcType " + jdbcType + " . "
+ "Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. "
+ "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 {View on GitHub (pinned to 008069adb1)
Solutions
- Inspect the Cause exception — the driver message names the failing parameter and reason
- Verify the #{param} javaType/typeHandler matches the actual runtime class of the argument
- Fix the data or column size if the cause is truncation/conversion at the driver level
Example fix
// before
#{createdOn,jdbcType=TIMESTAMP} <!-- value is java.time.LocalDateTime -->
// after
#{createdOn,typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler} Defensive patterns
Strategy: try-catch
Try / catch
try { ... } catch (TypeException e) {
Throwable root = e; while (root.getCause() != null) root = root.getCause();
// root is the driver error: log parameter index i and value type, fix binding
} Prevention
- Keep mapper javaType declarations in sync with entity field types
- Validate field lengths/value ranges before insert/update
- Log the bound parameter types when diagnosing persistent binding failures
When it happens
Trigger: A String longer than the column for setString; a handler mapped for one java type receiving another (e.g. DateTypeHandler given a LocalDate because the javaType attribute was wrong); dialect-specific setObject failures.
Common situations: resultMap/parameter javaType mismatches after refactoring entity fields; locale/charset data that the driver rejects; switching JDBC drivers with stricter conversion rules.
Related errors
- SqlRunner could not find a TypeHandler instance for {}
- Could not find type handler for Java type '" + propertyGener
- Could not set parameters for mapping: " + parameterMapping +
- ArrayType Handler requires SQL array or java array parameter
- Error determining JDBC type for column {}. Cause: {}
AI-assisted analysis of mybatis/mybatis-3@008069adb1 (2026-08-14).
Data as JSON: /api/errors/d5a268502c36183f.
Report an issue: GitHub.