{"record":{"id":"088b455a6600e387","repo":"mybatis/mybatis-3","slug":"do-not-know-how-to-create-an-instance-of-resul","errorCode":null,"errorMessage":"Do not know how to create an instance of \" + resultType","messagePattern":"Do not know how to create an instance of \" \\+ resultType","errorType":"exception","errorClass":"ExecutorException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java","lineNumber":793,"sourceCode":"  private Object createResultObject(ResultSetWrapper rsw, ResultMap resultMap, List<Class<?>> constructorArgTypes,\n      List<Object> constructorArgs, String columnPrefix, CacheKey parentRowKey) throws SQLException {\n\n    final Class<?> resultType = resultMap.getType();\n    final MetaClass metaType = MetaClass.forClass(resultType, reflectorFactory);\n    final List<ResultMapping> constructorMappings = resultMap.getConstructorResultMappings();\n    if (hasTypeHandlerForResultObject(rsw, resultType)) {\n      return createPrimitiveResultObject(rsw, resultMap, columnPrefix);\n    }\n    if (!constructorMappings.isEmpty()) {\n      return createParameterizedResultObject(rsw, resultType, constructorMappings, constructorArgTypes, constructorArgs,\n          columnPrefix, resultMap.hasResultMapsUsingConstructorCollection(), parentRowKey);\n    } else if (resultType.isInterface() || metaType.hasDefaultConstructor()) {\n      return objectFactory.create(resultType);\n    } else if (shouldApplyAutomaticMappings(resultMap, false)) {\n      return createByConstructorSignature(rsw, resultMap, columnPrefix, resultType, constructorArgTypes,\n          constructorArgs);\n    }\n    throw new ExecutorException(\"Do not know how to create an instance of \" + resultType);\n  }\n\n  Object createParameterizedResultObject(ResultSetWrapper rsw, Class<?> resultType,\n      List<ResultMapping> constructorMappings, List<Class<?>> constructorArgTypes, List<Object> constructorArgs,\n      String columnPrefix, boolean useCollectionConstructorInjection, CacheKey parentRowKey) {\n    boolean foundValues = false;\n\n    for (ResultMapping constructorMapping : constructorMappings) {\n      final Class<?> parameterType = constructorMapping.getJavaType();\n      final String column = constructorMapping.getColumn();\n      final Object value;\n      try {\n        if (constructorMapping.getNestedQueryId() != null) {\n          value = getNestedQueryConstructorValue(rsw, constructorMapping, columnPrefix);\n        } else if (JdbcType.CURSOR.equals(constructorMapping.getJdbcType())) {\n          List<?> result = (List<?>) getNestedCursorValue(rsw, constructorMapping, columnPrefix).get(0);\n          if (objectFactory.isCollection(parameterType)) {\n            MetaObject collection = configuration.newMetaObject(objectFactory.create(parameterType));","sourceCodeStart":775,"sourceCodeEnd":811,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java#L775-L811","documentation":"createResultObject exhausted every strategy to instantiate the result class: it is not a simple type-handler type, has no <constructor> mappings, has no default constructor (or is an interface with no default-ctor path via metaType), and automatic constructor matching either is disabled or found no usable constructor. MyBatis therefore has no way to build an instance of resultType.","triggerScenarios":"A resultMap whose type has only a non-empty constructor (immutable/Kotlin data class/value object), the mapping has no <constructor> block, shouldApplyAutomaticMappings is false (autoMappingBehavior=NONE) or createByConstructorSignature found no match, so the final throw executes.","commonSituations":"Immutable domain objects with all-args constructors and no no-arg constructor; autoMappingBehavior set to NONE globally; interfaces as resultType without a default implementation; constructor arg types not matching any sensible column set.","solutions":["Declare constructor mapping: <constructor><arg column=\"...\" javaType=\"...\"/>...</constructor> in the resultMap","Or add a public no-arg constructor (plus setters / automapping) to the result class","Set autoMappingBehavior=PARTIAL (default) so constructor automapping can be attempted","Annotate exactly one constructor with @AutomapConstructor when the class has several"],"exampleFix":"<!-- before -->\n<resultMap id=\"userMap\" type=\"com.example.User\"/>\n<!-- User only has User(Long id, String name) -->\n<!-- after -->\n<resultMap id=\"userMap\" type=\"com.example.User\">\n  <constructor>\n    <arg column=\"id\" javaType=\"long\"/>\n    <arg column=\"name\" javaType=\"string\"/>\n  </constructor>\n</resultMap>","handlingStrategy":"validation","validationCode":"// Fail fast if a resultType cannot be instantiated by any MyBatis strategy\nClass<?> t = User.class;\nboolean hasDefaultCtor = Arrays.stream(t.getConstructors()).anyMatch(c -> c.getParameterCount() == 0);\nif (!hasDefaultCtor && !t.isInterface() && noExplicitConstructorMapping(\"userMap\")) {\n  throw new IllegalStateException(t + \" needs a no-arg constructor or a <constructor> mapping\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Give immutable result classes an explicit <constructor> mapping or @AutomapConstructor","Keep a no-arg constructor on mutable entity classes","Leave autoMappingBehavior at PARTIAL unless mappings are fully explicit"],"tags":["mybatis","instantiation","constructor-mapping","resultmap","immutable"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}