@@ -887,23 +887,27 @@ private boolean applyNestedResultMappings(ResultSetWrapper rsw, ResultMap result
887
887
try {
888
888
final String columnPrefix = getColumnPrefix (parentPrefix , resultMapping );
889
889
final ResultMap nestedResultMap = getNestedResultMap (rsw .getResultSet (), nestedResultMapId , columnPrefix );
890
- Object ancestorObject = ancestorObjects .get (nestedResultMapId );
891
- if (ancestorObject != null ) {
892
- if (newObject ) {
893
- linkObjects (metaObject , resultMapping , ancestorObject ); // issue #385
894
- }
895
- } else {
896
- final CacheKey rowKey = createRowKey (nestedResultMap , rsw , columnPrefix );
897
- final CacheKey combinedKey = combineKeys (rowKey , parentRowKey );
898
- Object rowValue = nestedResultObjects .get (combinedKey );
899
- boolean knownValue = (rowValue != null );
900
- instantiateCollectionPropertyIfAppropriate (resultMapping , metaObject ); // mandatory
901
- if (anyNotNullColumnHasValue (resultMapping , columnPrefix , rsw .getResultSet ())) {
902
- rowValue = getRowValue (rsw , nestedResultMap , combinedKey , columnPrefix , rowValue );
903
- if (rowValue != null && !knownValue ) {
904
- linkObjects (metaObject , resultMapping , rowValue );
905
- foundValues = true ;
890
+ if (resultMapping .getColumnPrefix () == null ) {
891
+ // try to fill circular reference only when columnPrefix
892
+ // is not specified for the nested result map (issue #215)
893
+ Object ancestorObject = ancestorObjects .get (nestedResultMapId );
894
+ if (ancestorObject != null ) {
895
+ if (newObject ) {
896
+ linkObjects (metaObject , resultMapping , ancestorObject ); // issue #385
906
897
}
898
+ continue ;
899
+ }
900
+ }
901
+ final CacheKey rowKey = createRowKey (nestedResultMap , rsw , columnPrefix );
902
+ final CacheKey combinedKey = combineKeys (rowKey , parentRowKey );
903
+ Object rowValue = nestedResultObjects .get (combinedKey );
904
+ boolean knownValue = (rowValue != null );
905
+ instantiateCollectionPropertyIfAppropriate (resultMapping , metaObject ); // mandatory
906
+ if (anyNotNullColumnHasValue (resultMapping , columnPrefix , rsw )) {
907
+ rowValue = getRowValue (rsw , nestedResultMap , combinedKey , columnPrefix , rowValue );
908
+ if (rowValue != null && !knownValue ) {
909
+ linkObjects (metaObject , resultMapping , rowValue );
910
+ foundValues = true ;
907
911
}
908
912
}
909
913
} catch (SQLException e ) {
@@ -925,20 +929,26 @@ private String getColumnPrefix(String parentPrefix, ResultMapping resultMapping)
925
929
return columnPrefixBuilder .length () == 0 ? null : columnPrefixBuilder .toString ().toUpperCase (Locale .ENGLISH );
926
930
}
927
931
928
- private boolean anyNotNullColumnHasValue (ResultMapping resultMapping , String columnPrefix , ResultSet rs ) throws SQLException {
932
+ private boolean anyNotNullColumnHasValue (ResultMapping resultMapping , String columnPrefix , ResultSetWrapper rsw ) throws SQLException {
929
933
Set <String > notNullColumns = resultMapping .getNotNullColumns ();
930
- boolean anyNotNullColumnHasValue = true ;
931
934
if (notNullColumns != null && !notNullColumns .isEmpty ()) {
932
- anyNotNullColumnHasValue = false ;
935
+ ResultSet rs = rsw . getResultSet () ;
933
936
for (String column : notNullColumns ) {
934
937
rs .getObject (prependPrefix (column , columnPrefix ));
935
938
if (!rs .wasNull ()) {
936
- anyNotNullColumnHasValue = true ;
937
- break ;
939
+ return true ;
940
+ }
941
+ }
942
+ return false ;
943
+ } else if (columnPrefix != null ) {
944
+ for (String columnName : rsw .getColumnNames ()) {
945
+ if (columnName .toUpperCase ().startsWith (columnPrefix .toUpperCase ())) {
946
+ return true ;
938
947
}
939
948
}
949
+ return false ;
940
950
}
941
- return anyNotNullColumnHasValue ;
951
+ return true ;
942
952
}
943
953
944
954
private ResultMap getNestedResultMap (ResultSet rs , String nestedResultMapId , String columnPrefix ) throws SQLException {
0 commit comments