Draft
Fix user-defined resultMaps being replaced when enableBaseResultMapFlag=true#950
Conversation
Only replace auto-generated inline resultMaps in setRawSqlSourceMapper. Auto-generated maps have IDs starting with statementId + "-" (e.g. "-Inline" for XML resultType=, "-void"/"-TypeName" for annotations without @results). User-defined resultMaps (resultMap= or @resultMap) have unrelated IDs and are now left intact, preserving nested queries, discriminators, etc. Add NestedQueryTest to reproduce and verify the fix.
Copilot
AI
changed the title
[WIP] Fix nested query issue after upgrading to 5.0.0
Fix user-defined resultMaps being replaced when enableBaseResultMapFlag=true
Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
enableBaseResultMapFlag=true,MapperHelper.setRawSqlSourceMapper()was replacing user-configured resultMaps with the JPA-generatedBaseMapperResultMap, breaking nested queries (<association select=...>,<collection select=...>) and discriminators. The bug: the only guard wasresultMappings.isEmpty(), but a<resultMap>containing only a<discriminator>stores it outsideresultMappings, causing it to pass the check and get replaced.Changes
MapperHelper.setRawSqlSourceMapper()— tighten the replacement guard:MyBatis always names auto-generated inline resultMaps with a
statementId + "-"prefix (-Inlinefor XMLresultType=,-void/-TypeNamefor unannotated@Select). User-defined resultMaps (XML<resultMap id="...">or@ResultMap) have namespace-scoped IDs with no relation to any statement ID, so they never match and are left untouched.New
NestedQueryTest— covers three scenarios: resultMap with explicit mappings + nested select, association-only resultMap, and discriminator-only resultMap with nested selects in case maps (the last being the direct reproducer of the bug).