Skip to content

Commit 299e263

Browse files
committed
Fix for #318. Merged from 3.2.x branch
1 parent 66efde5 commit 299e263

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -445,15 +445,17 @@ private boolean applyAutomaticMappings(ResultSetWrapper rsw, ResultMap resultMap
445445
private void linkToParents(ResultSet rs, ResultMapping parentMapping, Object rowValue) throws SQLException {
446446
CacheKey parentKey = createKeyForMultipleResults(rs, parentMapping, parentMapping.getColumn(), parentMapping.getForeignColumn());
447447
List<PendingRelation> parents = pendingRelations.get(parentKey);
448-
for (PendingRelation parent : parents) {
449-
if (parent != null) {
450-
final Object collectionProperty = instantiateCollectionPropertyIfAppropriate(parent.propertyMapping, parent.metaObject);
451-
if (rowValue != null) {
452-
if (collectionProperty != null) {
453-
final MetaObject targetMetaObject = configuration.newMetaObject(collectionProperty);
454-
targetMetaObject.add(rowValue);
455-
} else {
456-
parent.metaObject.setValue(parent.propertyMapping.getProperty(), rowValue);
448+
if (parents != null) {
449+
for (PendingRelation parent : parents) {
450+
if (parent != null) {
451+
final Object collectionProperty = instantiateCollectionPropertyIfAppropriate(parent.propertyMapping, parent.metaObject);
452+
if (rowValue != null) {
453+
if (collectionProperty != null) {
454+
final MetaObject targetMetaObject = configuration.newMetaObject(collectionProperty);
455+
targetMetaObject.add(rowValue);
456+
} else {
457+
parent.metaObject.setValue(parent.propertyMapping.getProperty(), rowValue);
458+
}
457459
}
458460
}
459461
}

src/test/java/org/apache/ibatis/submitted/multipleresultsetswithassociation/CreateDB3.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
VALUES (1, 'Fred');
1717
INSERT INTO order_header(order_id, cust_name)
1818
VALUES (2, 'Barney');
19+
INSERT INTO order_header(order_id, cust_name)
20+
VALUES (3, 'Homer');
1921

2022
INSERT INTO order_detail(order_id, line_number, quantity, item_description)
2123
VALUES (1, 1, 1, 'Pen');

0 commit comments

Comments
 (0)