{"record":{"id":"57af28a333eda2f9","repo":"mybatis/mybatis-3","slug":"could-not-set-parameters-for-mapping-paramete","errorCode":null,"errorMessage":"Could not set parameters for mapping: \" + parameterMapping + \". Cause: \" + e","messagePattern":"Could not set parameters for mapping: \" \\+ parameterMapping \\+ \"\\. Cause: \" \\+ e","errorType":"exception","errorClass":"TypeException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/scripting/defaults/DefaultParameterHandler.java","lineNumber":176,"sourceCode":"              typeHandler = ObjectTypeHandler.INSTANCE;\n            }\n          } else if (typeHandler == null) {\n            if (propertyGenericType == null) {\n              propertyGenericType = value.getClass();\n            }\n            typeHandler = typeHandlerRegistry.getTypeHandler(propertyGenericType, actualJdbcType, null);\n          }\n          if (typeHandler == null) {\n            typeHandler = typeHandlerRegistry.getTypeHandler(actualJdbcType);\n          }\n          if (typeHandler == null) {\n            throw new TypeException(\"Could not find type handler for Java type '\" + propertyGenericType.getTypeName()\n                + \"' nor JDBC type '\" + actualJdbcType + \"'\");\n          }\n          try {\n            typeHandler.setParameter(ps, i + 1, value, jdbcType);\n          } catch (TypeException | SQLException e) {\n            throw new TypeException(\"Could not set parameters for mapping: \" + parameterMapping + \". Cause: \" + e, e);\n          }\n        }\n      }\n    }\n  }\n\n  private MetaObject getParamMetaObject() {\n    if (paramMetaObject != null) {\n      return paramMetaObject;\n    }\n    paramMetaObject = configuration.newMetaObject(parameterObject);\n    return paramMetaObject;\n  }\n\n  private JdbcType getParamJdbcType(PreparedStatement ps, int paramIndex) {\n    try {\n      if (paramMetaData == null) {\n        paramMetaData = ps.getParameterMetaData();","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/scripting/defaults/DefaultParameterHandler.java#L158-L194","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the nested Cause: fix the data/conversion problem it names (truncate strings, fix column sizes, convert value types before passing)","For null parameters add jdbcType: #{field,jdbcType=VARCHAR}","Debug/fix custom TypeHandler.setParameter to handle the failing value","Align the bean field type and jdbcType with the actual column type in the DB"],"exampleFix":"<!-- before -->\n#{remark}  <!-- null remark on Oracle -> driver error -->\n\n<!-- after -->\n#{remark,jdbcType=VARCHAR}","handlingStrategy":"try-catch","validationCode":"// pre-validate value sizes/conversions before executing, e.g.\nif (value instanceof String s && s.length() > COLUMN_SIZE) {\n  throw new IllegalArgumentException(\"Value too long for column\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  session.update(\"updateStmt\", params);\n} catch (PersistenceException e) {\n  Throwable cause = e.getCause();\n  if (cause instanceof TypeException && cause.getMessage().contains(\"Could not set parameters for mapping\")) {\n    // inspect parameterMapping in the message; fix value/jdbcType, then surface a clear error\n  } else throw e;\n}","preventionTips":["Always specify jdbcType for nullable parameters","Validate data lengths/types against column definitions before insert/update","Unit-test custom TypeHandler.setParameter against all value states including null"],"tags":["type-handler","jdbc","parameters","sql-exception","mybatis"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}