{"record":{"id":"e1e286d82a95cfff","repo":"mybatis/mybatis-3","slug":"a-query-was-run-and-no-result-maps-were-found-for","errorCode":null,"errorMessage":"A query was run and no Result Maps were found for the Mapped Statement '\" + mappedStatement.getId() + \"'. 'resultType' or 'resultMap' must be specified when there is no corresponding method.\"","messagePattern":"A query was run and no Result Maps were found for the Mapped Statement '\" \\+ mappedStatement\\.getId\\(\\) \\+ \"'\\. 'resultType' or 'resultMap' must be specified when there is no corresponding method\\.\"","errorType":"exception","errorClass":"ExecutorException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java","lineNumber":334,"sourceCode":"  }\n\n  private void closeResultSet(ResultSet rs) {\n    try {\n      if (rs != null) {\n        rs.close();\n      }\n    } catch (SQLException e) {\n      // ignore\n    }\n  }\n\n  private void cleanUpAfterHandlingResultSet() {\n    nestedResultObjects.clear();\n  }\n\n  private void validateResultMapsCount(ResultSetWrapper rsw, int resultMapCount) {\n    if (rsw != null && resultMapCount < 1) {\n      throw new ExecutorException(\n          \"A query was run and no Result Maps were found for the Mapped Statement '\" + mappedStatement.getId()\n              + \"'. 'resultType' or 'resultMap' must be specified when there is no corresponding method.\");\n    }\n  }\n\n  private void handleResultSet(ResultSetWrapper rsw, ResultMap resultMap, List<Object> multipleResults,\n      ResultMapping parentMapping) throws SQLException {\n    try {\n      if (parentMapping != null) {\n        handleRowValues(rsw, resultMap, null, RowBounds.DEFAULT, parentMapping);\n      } else if (resultHandler == null) {\n        DefaultResultHandler defaultResultHandler = new DefaultResultHandler(objectFactory);\n        handleRowValues(rsw, resultMap, defaultResultHandler, rowBounds, null);\n        multipleResults.add(defaultResultHandler.getResultList());\n      } else {\n        handleRowValues(rsw, resultMap, resultHandler, rowBounds, null);\n      }\n    } finally {","sourceCodeStart":316,"sourceCodeEnd":352,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java#L316-L352","documentation":"validateResultMapsCount fires when a statement produced a ResultSet but the MappedStatement declares zero result maps. Every query statement must tell MyBatis how to map rows, either via resultType or resultMap; without one there is no way to materialize rows.","triggerScenarios":"handleResultSets/handleCursorResultSets runs with rsw != null and mappedStatement.getResultMaps().size() < 1 — a <select> node with neither resultType nor resultMap, or a mapper method return type MyBatis cannot infer (e.g. void or an unresolvable generic).","commonSituations":"Hand-written mapper XML forgetting resultType on a new <select>; annotation @Select without a matching return type on the interface method; refactoring that removes resultType while renaming; using Map-returning methods with ambiguous signatures.","solutions":["Add resultType='com.example.Order' (or a resultMap reference) to the offending <select id=...> named in the message","For annotation mappers, give the method a concrete return type (Order, List<Order>, Map<String,Object>) so MyBatis can derive resultType","For statements invoked without a backing method, always declare the mapping explicitly in XML"],"exampleFix":"<!-- before -->\n<select id=\"selectOrders\" parameterType=\"long\">\n  SELECT * FROM orders WHERE customer_id = #{id}\n</select>\n<!-- after -->\n<select id=\"selectOrders\" parameterType=\"long\" resultType=\"com.example.Order\">\n  SELECT * FROM orders WHERE customer_id = #{id}\n</select>","handlingStrategy":"validation","validationCode":"// Fail fast at startup: every select statement must declare a result mapping\nfor (String id : sqlSessionFactory.getConfiguration().getMappedStatementNames()) {\n  MappedStatement ms = sqlSessionFactory.getConfiguration().getMappedStatement(id);\n  if (ms.getSqlCommandType() == SqlCommandType.SELECT && ms.getResultMaps().isEmpty()) {\n    throw new IllegalStateException(\"Statement missing resultType/resultMap: \" + id);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always write resultType when creating a <select>","Give mapper interface methods concrete return types","Add a config validation integration test that executes every mapped select in a test DB"],"tags":["mybatis","resultmap","resulttype","mapper","configuration"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}