{"record":{"id":"36af1def0f0e16c8","repo":"mybatis/mybatis-3","slug":"there-is-no-default-constructor-for","errorCode":null,"errorMessage":"There is no default constructor for {}","messagePattern":"There is no default constructor for (.+?)","errorType":"exception","errorClass":"ReflectionException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/reflection/Reflector.java","lineNumber":371,"sourceCode":"      return false;\n    }\n    return true;\n  }\n\n  /**\n   * Gets the name of the class the instance provides information for.\n   *\n   * @return The class name\n   */\n  public Class<?> getType() {\n    return clazz;\n  }\n\n  public Constructor<?> getDefaultConstructor() {\n    if (defaultConstructor != null) {\n      return defaultConstructor;\n    }\n    throw new ReflectionException(\"There is no default constructor for \" + clazz);\n  }\n\n  public boolean hasDefaultConstructor() {\n    return defaultConstructor != null;\n  }\n\n  public Invoker getSetInvoker(String propertyName) {\n    Invoker method = setMethods.get(propertyName);\n    if (method == null) {\n      throw new ReflectionException(\"There is no setter for property named '\" + propertyName + \"' in '\" + clazz + \"'\");\n    }\n    return method;\n  }\n\n  public Invoker getGetInvoker(String propertyName) {\n    Invoker method = getMethods.get(propertyName);\n    if (method == null) {\n      throw new ReflectionException(\"There is no getter for property named '\" + propertyName + \"' in '\" + clazz + \"'\");","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/reflection/Reflector.java#L353-L389","documentation":"Reflector.getDefaultConstructor() throws when the reflected class has no public no-arg constructor. MyBatis instantiates result types, parameter types, and typeHandler-owning classes through this path, and without a default constructor it cannot create the instance.","triggerScenarios":"A resultType/parameterType class (or javaType handled by a factory) whose only constructors take arguments, reached via ObjectFactory.create(type) during result mapping or parameter processing.","commonSituations":"DTOs with only an all-args constructor (common with Lombok @AllArgsConstructor without @NoArgsConstructor); Kotlin data classes without a no-arg constructor (or kotlin-noarg plugin); immutable value objects.","solutions":["Add a public no-arg constructor to the class (plus @NoArgsConstructor alongside Lombok @AllArgsConstructor).","Map through a constructor instead: <constructor> elements in the resultMap, or argNameBasedConstructorAutomapping/autoMappingBehavior, so MyBatis uses the arg-taking constructor.","For immutable objects, use a custom ObjectFactory or a TypeHandler/ResultHandler that builds the object yourself."],"exampleFix":"// before\n@AllArgsConstructor\npublic class User { private final Long id; }\n// after\n@NoArgsConstructor\n@AllArgsConstructor\npublic class User { private Long id; }","handlingStrategy":"validation","validationCode":"boolean instantiable = new ReflectorFactory().createForType(User.class).hasDefaultConstructor();\nif (!instantiable) { /* add no-arg ctor or map via <constructor> */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Give every result/parameter DTO a no-arg constructor (or Lombok @NoArgsConstructor) by convention.","For immutable classes, plan <constructor> mappings from the start instead of setter-based automapping."],"tags":["mybatis","reflection","constructor","lombok","kotlin"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}