{"record":{"id":"e74656977b9f1e7d","repo":"mybatis/mybatis-3","slug":"there-should-be-the-same-number-of-columns-and-for","errorCode":null,"errorMessage":"There should be the same number of columns and foreignColumns in property {}","messagePattern":"There should be the same number of columns and foreignColumns in property (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/mapping/ResultMapping.java","lineNumber":181,"sourceCode":"        throw new IllegalStateException(\n            \"Cannot define both nestedQueryId and nestedResultMapId in property \" + resultMapping.property);\n      }\n      // Issue #4 and GH #39: column is optional only in nested resultMaps but not in the rest\n      if (resultMapping.nestedResultMapId == null && resultMapping.column == null\n          && resultMapping.composites.isEmpty()) {\n        throw new IllegalStateException(\"Mapping is missing column attribute for property \" + resultMapping.property);\n      }\n      if (resultMapping.getResultSet() != null) {\n        int numColumns = 0;\n        if (resultMapping.column != null) {\n          numColumns = resultMapping.column.split(\",\").length;\n        }\n        int numForeignColumns = 0;\n        if (resultMapping.foreignColumn != null) {\n          numForeignColumns = resultMapping.foreignColumn.split(\",\").length;\n        }\n        if (numColumns != numForeignColumns) {\n          throw new IllegalStateException(\n              \"There should be the same number of columns and foreignColumns in property \" + resultMapping.property);\n        }\n      }\n    }\n\n    public Builder column(String column) {\n      resultMapping.column = column;\n      return this;\n    }\n  }\n\n  public String getProperty() {\n    return property;\n  }\n\n  public String getColumn() {\n    return column;\n  }","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/mapping/ResultMapping.java#L163-L199","documentation":"Thrown by ResultMapping.Builder.validate() for joined/multiple result sets (resultSet attribute present). When a mapping declares a resultSet, MyBatis pairs each column with a foreignColumn to correlate rows across result sets, so both lists must have the same length after splitting on commas.","triggerScenarios":"An <association> or <collection> with resultSet=\"...\" where the comma-separated lists in column and foreignColumn differ in length, e.g. column=\"a,b\" with foreignColumn=\"c\".","commonSituations":"Stored procedures returning multiple result sets joined by composite keys; developer adds one side of a two-part key but not the other; stray/missing commas in the lists.","solutions":["Count entries in column and foreignColumn and make them match (column=\"a,b\" foreignColumn=\"x,y\").","Remove stray spaces or empty segments caused by trailing/double commas in either attribute.","If the correlation key is single-column, keep exactly one column and one foreignColumn."],"exampleFix":"<!-- before -->\n<association property=\"author\" javaType=\"Author\" resultSet=\"authorsRS\" column=\"id,tenant\" foreignColumn=\"authorId\"/>\n<!-- after -->\n<association property=\"author\" javaType=\"Author\" resultSet=\"authorsRS\" column=\"id,tenant\" foreignColumn=\"authorId,authorTenant\"/>","handlingStrategy":"validation","validationCode":"int cols = column == null ? 0 : column.split(\",\").length;\nint foreign = foreignColumn == null ? 0 : foreignColumn.split(\",\").length;\nif (resultSet != null && cols != foreign) throw new IllegalArgumentException(\"column/foreignColumn count mismatch\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always write column and foreignColumn as matching comma lists and count them together.","Keep correlation keys in one place (a constant or comment) in stored-procedure mappings."],"tags":["mybatis","resultmap","stored-procedure","multiple-resultsets"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}