@@ -532,7 +532,7 @@ private boolean applyPropertyMappings(ResultSetWrapper rsw, ResultMap resultMap,
532532 final List <ResultMapping > propertyMappings = resultMap .getPropertyResultMappings ();
533533 for (ResultMapping propertyMapping : propertyMappings ) {
534534 String column = prependPrefix (propertyMapping .getColumn (), columnPrefix );
535- if (propertyMapping .getNestedResultMapId () != null ) {
535+ if (propertyMapping .getNestedResultMapId () != null && ! JdbcType . CURSOR . equals ( propertyMapping . getJdbcType ()) ) {
536536 // the user added a column attribute to a nested result map, ignore it
537537 column = null ;
538538 }
@@ -568,6 +568,11 @@ private Object getPropertyMappingValue(ResultSet rs, MetaObject metaResultObject
568568 if (propertyMapping .getNestedQueryId () != null ) {
569569 return getNestedQueryMappingValue (rs , metaResultObject , propertyMapping , lazyLoader , columnPrefix );
570570 }
571+ if (JdbcType .CURSOR .equals (propertyMapping .getJdbcType ())) {
572+ List <Object > results = getNestedCursorValue (rs , propertyMapping , columnPrefix );
573+ linkObjects (metaResultObject , propertyMapping , results .get (0 ), true );
574+ return metaResultObject .getValue (propertyMapping .getProperty ());
575+ }
571576 if (propertyMapping .getResultSet () != null ) {
572577 addPendingChildRelation (rs , metaResultObject , propertyMapping ); // TODO is that OK?
573578 return DEFERRED ;
@@ -578,6 +583,18 @@ private Object getPropertyMappingValue(ResultSet rs, MetaObject metaResultObject
578583 }
579584 }
580585
586+ private List <Object > getNestedCursorValue (ResultSet rs , ResultMapping propertyMapping , String parentColumnPrefix )
587+ throws SQLException {
588+ final String column = prependPrefix (propertyMapping .getColumn (), parentColumnPrefix );
589+ ResultMap nestedResultMap = resolveDiscriminatedResultMap (rs ,
590+ configuration .getResultMap (propertyMapping .getNestedResultMapId ()),
591+ getColumnPrefix (parentColumnPrefix , propertyMapping ));
592+ ResultSetWrapper rsw = new ResultSetWrapper (rs .getObject (column , ResultSet .class ), configuration );
593+ List <Object > results = new ArrayList <>();
594+ handleResultSet (rsw , nestedResultMap , results , null );
595+ return results ;
596+ }
597+
581598 private List <UnMappedColumnAutoMapping > createAutomaticMappings (ResultSetWrapper rsw , ResultMap resultMap ,
582599 MetaObject metaObject , String columnPrefix ) throws SQLException {
583600 final String mapKey = resultMap .getId () + ":" + columnPrefix ;
@@ -761,6 +778,15 @@ Object createParameterizedResultObject(ResultSetWrapper rsw, Class<?> resultType
761778 try {
762779 if (constructorMapping .getNestedQueryId () != null ) {
763780 value = getNestedQueryConstructorValue (rsw .getResultSet (), constructorMapping , columnPrefix );
781+ } else if (JdbcType .CURSOR .equals (constructorMapping .getJdbcType ())) {
782+ List <?> result = (List <?>) getNestedCursorValue (rsw .getResultSet (), constructorMapping , columnPrefix ).get (0 );
783+ if (objectFactory .isCollection (parameterType )) {
784+ MetaObject collection = configuration .newMetaObject (objectFactory .create (parameterType ));
785+ collection .addAll ((List <?>) result );
786+ value = collection .getOriginalObject ();
787+ } else {
788+ value = toSingleObj (result );
789+ }
764790 } else if (constructorMapping .getNestedResultMapId () != null ) {
765791 final String constructorColumnPrefix = getColumnPrefix (columnPrefix , constructorMapping );
766792 final ResultMap resultMap = resolveDiscriminatedResultMap (rsw .getResultSet (),
@@ -1527,10 +1553,19 @@ private void createRowKeyForMap(ResultSetWrapper rsw, CacheKey cacheKey) throws
15271553 }
15281554
15291555 private void linkObjects (MetaObject metaObject , ResultMapping resultMapping , Object rowValue ) {
1556+ linkObjects (metaObject , resultMapping , rowValue , false );
1557+ }
1558+
1559+ private void linkObjects (MetaObject metaObject , ResultMapping resultMapping , Object rowValue ,
1560+ boolean isNestedCursorResult ) {
15301561 final Object collectionProperty = instantiateCollectionPropertyIfAppropriate (resultMapping , metaObject );
15311562 if (collectionProperty != null ) {
15321563 final MetaObject targetMetaObject = configuration .newMetaObject (collectionProperty );
1533- targetMetaObject .add (rowValue );
1564+ if (isNestedCursorResult ) {
1565+ targetMetaObject .addAll ((List <?>) rowValue );
1566+ } else {
1567+ targetMetaObject .add (rowValue );
1568+ }
15341569
15351570 // it is possible for pending creations to get set via property mappings,
15361571 // keep track of these, so we can rebuild them.
@@ -1543,10 +1578,16 @@ private void linkObjects(MetaObject metaObject, ResultMapping resultMapping, Obj
15431578 pendingPccRelations .put (originalObject , pendingRelation );
15441579 }
15451580 } else {
1546- metaObject .setValue (resultMapping .getProperty (), rowValue );
1581+ metaObject .setValue (resultMapping .getProperty (),
1582+ isNestedCursorResult ? toSingleObj ((List <?>) rowValue ) : rowValue );
15471583 }
15481584 }
15491585
1586+ private Object toSingleObj (List <?> list ) {
1587+ // Even if there are multiple elements, silently returns the first one.
1588+ return list .isEmpty () ? null : list .get (0 );
1589+ }
1590+
15501591 private Object instantiateCollectionPropertyIfAppropriate (ResultMapping resultMapping , MetaObject metaObject ) {
15511592 final String propertyName = resultMapping .getProperty ();
15521593 Object propertyValue = metaObject .getValue (propertyName );
0 commit comments