{"record":{"id":"e0f3b6f70670ca44","repo":"mybatis/mybatis-3","slug":"wrong-namespace-expected-currentnamespace-but","errorCode":null,"errorMessage":"Wrong namespace. Expected '{currentNamespace}' but found '{currentNamespace}'.","messagePattern":"Wrong namespace\\. Expected '(.+?)' but found '(.+?)'\\.","errorType":"exception","errorClass":"BuilderException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/builder/MapperBuilderAssistant.java","lineNumber":81,"sourceCode":"  private boolean unresolvedCacheRef; // issue #676\n\n  public MapperBuilderAssistant(Configuration configuration, String resource) {\n    super(configuration);\n    ErrorContext.instance().resource(resource);\n    this.resource = resource;\n  }\n\n  public String getCurrentNamespace() {\n    return currentNamespace;\n  }\n\n  public void setCurrentNamespace(String currentNamespace) {\n    if (currentNamespace == null) {\n      throw new BuilderException(\"The mapper element requires a namespace attribute to be specified.\");\n    }\n\n    if (this.currentNamespace != null && !this.currentNamespace.equals(currentNamespace)) {\n      throw new BuilderException(\n          \"Wrong namespace. Expected '\" + this.currentNamespace + \"' but found '\" + currentNamespace + \"'.\");\n    }\n\n    this.currentNamespace = currentNamespace;\n  }\n\n  public String applyCurrentNamespace(String base, boolean isReference) {\n    if (base == null) {\n      return null;\n    }\n    if (isReference) {\n      // is it qualified with any namespace yet?\n      if (base.contains(\".\")) {\n        return base;\n      }\n    } else {\n      // is it qualified with this namespace yet?\n      if (base.startsWith(currentNamespace + \".\")) {","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/builder/MapperBuilderAssistant.java#L63-L99","documentation":"setCurrentNamespace() enforces that one MapperBuilderAssistant instance (one mapper resource) is bound to exactly one namespace. If a different namespace string arrives after the first was set - nested <mapper> definitions, multiple root elements, or parser reuse across files - MyBatis throws this BuilderException showing expected vs found.","triggerScenarios":"An XML file containing statements that applyCurrentNamespace resolves to a second namespace, e.g. cross-file references during incomplete parsing; an embedded mapper element inside another mapper file; tools that reuse the same assistant for multiple mapper files; XML structure issues (duplicated root elements after a bad merge).","commonSituations":"Bad merges leaving two <mapper> roots in one file; code generators emitting nested mapper elements; custom XML parsing pipelines reusing builder assistants.","solutions":["Inspect the mapper XML named in the error context: ensure exactly one root <mapper> with one namespace attribute","Split statements belonging to different namespaces into separate files, one namespace per file","If generating XML, ensure each emitted file has a single root element and a fixed namespace"],"exampleFix":"<!-- before (one file, two roots after bad merge) -->\n<mapper namespace=\"com.example.A\">...</mapper>\n<mapper namespace=\"com.example.B\">...</mapper>\n<!-- after -->\n<!-- file A.xml -->\n<mapper namespace=\"com.example.A\">...</mapper>\n<!-- file B.xml -->\n<mapper namespace=\"com.example.B\">...</mapper>","handlingStrategy":"validation","validationCode":"// CI check: each mapper file has exactly one root <mapper> element and one namespace\n// DocumentBuilderFactory is namespace-aware; reject files with >1 <mapper> root child","typeGuard":null,"tryCatchPattern":null,"preventionTips":["One namespace per XML file; split multi-namespace files","Review merge conflicts in mapper XML carefully - duplicated roots are a common artifact","If generating mappers, emit one file per namespace"],"tags":["mybatis","builder","namespace","xml-configuration"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}