Index: src/com/ibatis/sqlmap/engine/mapping/result/ResultMap.java =================================================================== --- src/com/ibatis/sqlmap/engine/mapping/result/ResultMap.java (revision 677639) +++ src/com/ibatis/sqlmap/engine/mapping/result/ResultMap.java Thu Jul 17 14:11:11 EDT 2008 @@ -443,17 +443,26 @@ } } + //JIRA 375 "Provide a way for not creating items from nested ResultMaps when the items contain only null values" + boolean subResultObjectAbsent = false; + if(mapping.getNotNullColumn() != null) { + if(statementScope.getResultSet().getObject(mapping.getNotNullColumn()) == null) { + subResultObjectAbsent = true; + } + } + if(!subResultObjectAbsent) { - values = resultMap.getResults(statementScope, statementScope.getResultSet()); - if (statementScope.isRowDataFound()) { - Object o = resultMap.setResultObjectValues(statementScope, null, values); - if (o != NO_VALUE) { - if (obj != null && obj instanceof Collection) { - ((Collection) obj).add(o); - } else { - PROBE.setObject(resultObject, propertyName, o); - } - } - } + values = resultMap.getResults(statementScope, statementScope.getResultSet()); + if (statementScope.isRowDataFound()) { + Object o = resultMap.setResultObjectValues(statementScope, null, values); + if (o != NO_VALUE) { + if (obj != null && obj instanceof Collection) { + ((Collection) obj).add(o); + } else { + PROBE.setObject(resultObject, propertyName, o); + } + } + } + } } catch (SQLException e) { throw new SqlMapException("Error getting nested result map values for '" + mapping.getPropertyName() + "'. Cause: " + e, e); } Index: src/com/ibatis/sqlmap/engine/config/ResultMapConfig.java =================================================================== --- src/com/ibatis/sqlmap/engine/config/ResultMapConfig.java (revision 677639) +++ src/com/ibatis/sqlmap/engine/config/ResultMapConfig.java Thu Jul 17 14:05:22 EDT 2008 @@ -101,7 +101,7 @@ discriminator.addSubMap(value.toString(), resultMap); } - public void addResultMapping(String propertyName, String columnName, Integer columnIndex, Class javaClass, String jdbcType, String nullValue, String statementName, String resultMapName, Object impl) { + public void addResultMapping(String propertyName, String columnName, Integer columnIndex, Class javaClass, String jdbcType, String nullValue, String notNullColumn, String statementName, String resultMapName, Object impl) { errorContext.setObjectId(propertyName + " mapping of the " + resultMap.getId() + " result map"); TypeHandler handler; if (impl != null) { @@ -121,6 +121,7 @@ mapping.setJdbcTypeName(jdbcType); mapping.setTypeHandler(handler); mapping.setNullValue(nullValue); + mapping.setNotNullColumn(notNullColumn); mapping.setStatementName(statementName); mapping.setNestedResultMapName(resultMapName); if (resultMapName != null && resultMapName.length() > 0) { Index: src/com/ibatis/sqlmap/engine/mapping/result/ResultMapping.java =================================================================== --- src/com/ibatis/sqlmap/engine/mapping/result/ResultMapping.java (revision 677639) +++ src/com/ibatis/sqlmap/engine/mapping/result/ResultMapping.java Thu Jul 17 14:06:37 EDT 2008 @@ -30,6 +30,7 @@ private int jdbcType; private String jdbcTypeName; private String nullValue; + private String notNullColumn; private String statementName; private Class javaType; @@ -178,6 +179,24 @@ } /** + * Getter for the name of the column to check for null before instantiating a nested resultMapping value + * + * @return - the null substitution + */ + public String getNotNullColumn() { + return notNullColumn; + } + + /** + * Setter for the name of the column to check for null before instantiating a nested resultMapping value + * + * @param notNullColumn - the column name + */ + public void setNotNullColumn(String notNullColumn) { + this.notNullColumn = notNullColumn; + } + + /** * Getter for the name of the statement * * @return - the name Index: src/com/ibatis/sqlmap/engine/builder/xml/SqlMapParser.java =================================================================== --- src/com/ibatis/sqlmap/engine/builder/xml/SqlMapParser.java (revision 677639) +++ src/com/ibatis/sqlmap/engine/builder/xml/SqlMapParser.java Thu Jul 17 14:02:32 EDT 2008 @@ -243,6 +243,7 @@ String statementName = childAttributes.getProperty("select"); String resultMapName = childAttributes.getProperty("resultMap"); String callback = childAttributes.getProperty("typeHandler"); + String notNullColumn = childAttributes.getProperty("notNullColumn"); state.getConfig().getErrorContext().setMoreInfo("Check the result mapping property type or name."); Class javaClass = null; @@ -275,7 +276,7 @@ } } - state.getResultConfig().addResultMapping(propertyName, columnName, columnIndex, javaClass, jdbcType, nullValue, statementName, resultMapName, typeHandlerImpl); + state.getResultConfig().addResultMapping(propertyName, columnName, columnIndex, javaClass, jdbcType, nullValue, notNullColumn, statementName, resultMapName, typeHandlerImpl); } }); Index: src/com/ibatis/sqlmap/engine/builder/xml/sql-map-2.dtd =================================================================== --- src/com/ibatis/sqlmap/engine/builder/xml/sql-map-2.dtd (revision 677639) +++ src/com/ibatis/sqlmap/engine/builder/xml/sql-map-2.dtd Thu Jul 17 14:12:01 EDT 2008 @@ -91,6 +91,7 @@ columnIndex CDATA #IMPLIED jdbcType CDATA #IMPLIED nullValue CDATA #IMPLIED +notNullColumn CDATA #IMPLIED select CDATA #IMPLIED resultMap CDATA #IMPLIED typeHandler CDATA #IMPLIED