@@ -75,6 +75,7 @@ public class DefaultResultSetHandler implements ResultSetHandler {
75
75
// nested resultmaps
76
76
private final Map <CacheKey , Object > nestedResultObjects = new HashMap <CacheKey , Object >();
77
77
private final Map <CacheKey , Object > ancestorObjects = new HashMap <CacheKey , Object >();
78
+ private final Map <String , String > ancestorColumnPrefix = new HashMap <String , String >();
78
79
79
80
// multiple resultsets
80
81
private final Map <String , ResultMapping > nextResultMaps = new HashMap <String , ResultMapping >();
@@ -215,6 +216,7 @@ private void closeResultSet(ResultSet rs) {
215
216
216
217
private void cleanUpAfterHandlingResultSet () {
217
218
nestedResultObjects .clear ();
219
+ ancestorColumnPrefix .clear ();
218
220
}
219
221
220
222
private void validateResultMapsCount (ResultSetWrapper rsw , int resultMapCount ) {
@@ -742,10 +744,11 @@ private void handleRowValuesForNestedResultMap(ResultSetWrapper rsw, ResultMap r
742
744
//
743
745
744
746
private Object getRowValue (ResultSetWrapper rsw , ResultMap resultMap , CacheKey combinedKey , CacheKey absoluteKey , String columnPrefix , Object partialObject ) throws SQLException {
747
+ final String resultMapId = resultMap .getId ();
745
748
Object resultObject = partialObject ;
746
749
if (resultObject != null ) {
747
750
final MetaObject metaObject = configuration .newMetaObject (resultObject );
748
- ancestorObjects . put (absoluteKey , resultObject );
751
+ putAncestor (absoluteKey , resultObject , resultMapId , columnPrefix );
749
752
applyNestedResultMappings (rsw , resultMap , metaObject , columnPrefix , combinedKey , false );
750
753
ancestorObjects .remove (absoluteKey );
751
754
} else {
@@ -758,7 +761,7 @@ private Object getRowValue(ResultSetWrapper rsw, ResultMap resultMap, CacheKey c
758
761
foundValues = applyAutomaticMappings (rsw , resultMap , metaObject , columnPrefix ) || foundValues ;
759
762
}
760
763
foundValues = applyPropertyMappings (rsw , resultMap , metaObject , lazyLoader , columnPrefix ) || foundValues ;
761
- ancestorObjects . put (absoluteKey , resultObject );
764
+ putAncestor (absoluteKey , resultObject , resultMapId , columnPrefix );
762
765
foundValues = applyNestedResultMappings (rsw , resultMap , metaObject , columnPrefix , combinedKey , true ) || foundValues ;
763
766
ancestorObjects .remove (absoluteKey );
764
767
foundValues = (lazyLoader != null && lazyLoader .size () > 0 ) || foundValues ;
@@ -769,6 +772,13 @@ private Object getRowValue(ResultSetWrapper rsw, ResultMap resultMap, CacheKey c
769
772
return resultObject ;
770
773
}
771
774
775
+ private void putAncestor (CacheKey rowKey , Object resultObject , String resultMapId , String columnPrefix ) {
776
+ if (!ancestorColumnPrefix .containsKey (resultMapId )) {
777
+ ancestorColumnPrefix .put (resultMapId , columnPrefix );
778
+ }
779
+ ancestorObjects .put (rowKey , resultObject );
780
+ }
781
+
772
782
//
773
783
// NESTED RESULT MAP (JOIN MAPPING)
774
784
//
@@ -781,11 +791,16 @@ private boolean applyNestedResultMappings(ResultSetWrapper rsw, ResultMap result
781
791
try {
782
792
final String columnPrefix = getColumnPrefix (parentPrefix , resultMapping );
783
793
final ResultMap nestedResultMap = getNestedResultMap (rsw .getResultSet (), nestedResultMapId , columnPrefix );
784
- final CacheKey rowKey = createRowKey (nestedResultMap , rsw , columnPrefix );
785
- final Object ancestorObject = ancestorObjects .get (rowKey );
794
+ CacheKey rowKey = null ;
795
+ Object ancestorObject = null ;
796
+ if (ancestorColumnPrefix .containsKey (nestedResultMapId )) {
797
+ rowKey = createRowKey (nestedResultMap , rsw , ancestorColumnPrefix .get (nestedResultMapId ));
798
+ ancestorObject = ancestorObjects .get (rowKey );
799
+ }
786
800
if (ancestorObject != null ) {
787
801
if (newObject ) metaObject .setValue (resultMapping .getProperty (), ancestorObject );
788
802
} else {
803
+ rowKey = createRowKey (nestedResultMap , rsw , columnPrefix );
789
804
final CacheKey combinedKey = combineKeys (rowKey , parentRowKey );
790
805
Object rowValue = nestedResultObjects .get (combinedKey );
791
806
boolean knownValue = (rowValue != null );
0 commit comments