NPE if using columnIndex in combination with select in resultMap
----------------------------------------------------------------

                 Key: IBATIS-429
                 URL: https://issues.apache.org/jira/browse/IBATIS-429
             Project: iBatis for Java
          Issue Type: Bug
          Components: SQL Maps
    Affects Versions: 2.3.0
         Environment: any system I suppose
            Reporter: Bodo Junglas
            Priority: Minor


If you try to create a resultMap only using columnIndex that contains a 1:N 
relation it would be convenient to add a line like
<result property="someList" columnIndex="indexOfPrimaryKey" 
select="select-other-table"/>

Doing so will end up with a NullPointerException in 
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap Line 579 
(prepareBeanParameterObject).
Obviously the current version only supports column by name but not by index.

Proposed patch:
I'd say that in the prepareBeanParameterObject() Method the lines
[...]
    String complexName = mapping.getColumnName();

    if (complexName.indexOf('=') > -1
        || complexName.indexOf(',') > -1) {
      StringTokenizer parser = new StringTokenizer(complexName, "{}=, ", false);
[...]
should be extended to
[...]
    String complexName = mapping.getColumnName();

    if (complexName == null ) {
        int columnIndex = mapping.getColumnIndex();
        TypeHandler propTypeHandler = 
typeHandlerFactory.getTypeHandler(parameterType);
        if (propTypeHandler == null) {
        propTypeHandler = typeHandlerFactory.getUnkownTypeHandler();
      }
      parameterObject = propTypeHandler.getResult(rs, columnIndex);
    } else if (complexName.indexOf('=') > -1
               || complexName.indexOf(',') > -1) {
      StringTokenizer parser = new StringTokenizer(complexName, "{}=, ", false);
[...]

The prepareDomParameterObject might be patched too

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to