{"record":{"id":"1ff57fd02948c678","repo":"mybatis/mybatis-3","slug":"could-not-set-property-of-with-value","errorCode":null,"errorMessage":"Could not set property '{}' of '{}' with value '{}' Cause: {}","messagePattern":"Could not set property '(.+?)' of '(.+?)' with value '(.+?)' Cause: (.+?)","errorType":"exception","errorClass":"ReflectionException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/reflection/wrapper/BeanWrapper.java","lineNumber":212,"sourceCode":"    } catch (RuntimeException e) {\n      throw e;\n    } catch (Throwable t) {\n      throw new ReflectionException(\n          \"Could not get property '\" + prop.getName() + \"' from \" + object.getClass() + \".  Cause: \" + t.toString(), t);\n    }\n  }\n\n  private void setBeanProperty(PropertyTokenizer prop, Object object, Object value) {\n    try {\n      Invoker method = metaClass.getSetInvoker(prop.getName());\n      Object[] params = { value };\n      try {\n        method.invoke(object, params);\n      } catch (Throwable t) {\n        throw ExceptionUtil.unwrapThrowable(t);\n      }\n    } catch (Throwable t) {\n      throw new ReflectionException(\"Could not set property '\" + prop.getName() + \"' of '\" + object.getClass()\n          + \"' with value '\" + value + \"' Cause: \" + t.toString(), t);\n    }\n  }\n\n  @Override\n  public boolean isCollection() {\n    return false;\n  }\n\n  @Override\n  public void add(Object element) {\n    throw new UnsupportedOperationException();\n  }\n\n  @Override\n  public <E> void addAll(List<E> list) {\n    throw new UnsupportedOperationException();\n  }","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/reflection/wrapper/BeanWrapper.java#L194-L230","documentation":"BeanWrapper.setBeanProperty invokes the property's write method via reflection. If the setter throws — most often IllegalArgumentException from a type mismatch between the supplied value and the setter parameter, or NPE inside custom setter logic — MyBatis wraps it in a ReflectionException naming the property, owner class, value, and cause. The Cause string identifies whether it is a conversion problem or setter logic failing.","triggerScenarios":"Result mapping feeds a String column value into an int setter (or any column-to-field type mismatch); a custom setter with validation that throws; mapping a null into a primitive setter; Enum vs String mismatch between JDBC value and property type.","commonSituations":"Column type changes in the DB (VARCHAR to NUMERIC) without updating the bean; resultMap jdbcType/javaType mismatches; DB nulls mapped into primitive fields; custom setters enforcing invariants that incoming data violates.","solutions":["Check the Cause: for IllegalArgumentException align the property type with the incoming value (add a typeHandler or change the field type)","Use wrapper types (Integer instead of int) for nullable columns","Register/select the correct TypeHandler in the resultMap mapping for the mismatched property","Fix or relax custom setter validation that rejects the mapped data"],"exampleFix":"<!-- before -->\n<result property=\"count\" column=\"count\" /> <!-- column is VARCHAR, field is int -->\n\n<!-- after -->\n<result property=\"count\" column=\"count\" typeHandler=\"org.apache.ibatis.type.IntegerTypeHandler\" />","handlingStrategy":"try-catch","validationCode":"// before mapping, sanity-check value type against the setter parameter type\nClass<?> expected = metaClass.getSetterType(\"count\");\nif (value != null && !expected.isAssignableFrom(value.getClass())\n    && !(expected.isPrimitive() || Number.class.isAssignableFrom(expected) /* conversions */)) {\n  value = convert(value, expected); // your conversion or typeHandler\n}","typeGuard":null,"tryCatchPattern":"try {\n  metaObject.setValue(\"count\", rawValue);\n} catch (ReflectionException e) {\n  Throwable cause = e.getCause();\n  if (cause instanceof IllegalArgumentException) {\n    // type mismatch: convert value or configure a typeHandler, then retry once\n  } else throw e;\n}","preventionTips":["Keep bean field types aligned with column types; use typeHandlers for conversions","Use wrapper types for nullable columns","After DB schema changes, re-verify resultMap property types"],"tags":["reflection","setter","type-mismatch","result-mapping","mybatis"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}