You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by "S Boyd (JIRA)" <ib...@incubator.apache.org> on 2005/03/15 05:00:08 UTC

[jira] Commented: (IBATIS-45) ProbeExceptions with complex beans

     [ http://issues.apache.org/jira/browse/IBATIS-45?page=comments#action_60852 ]
     
S Boyd commented on IBATIS-45:
------------------------------

You will need to modify the while loop in the following two methods found in both GenericProbe and ComplexBeanProbe to completely fix this bug:

 private Class getClassPropertyTypeForGetter(Class type, String name) {

    if (name.indexOf('.') > -1) {
      StringTokenizer parser = new StringTokenizer(name, ".");
      while (parser.hasMoreTokens()) {
        name = parser.nextToken();
        if(Map.class.isAssignableFrom(type)){// Map found
        	// Sets typeHandler to unknown
        	// any other subproperties are unknown so return
        	return Object.class; 
        }
        type = ClassInfo.getInstance(type).getGetterType(name);
      }
    } else {
      type = ClassInfo.getInstance(type).getGetterType(name);
    }

    return type;
  }

  /**
   * Returns the class that the setter expects to receive as a parameter when
   * setting a property value.
   *
   * @param type The class to check
   * @param name The name of the property
   * @return The type of the property
   */
  private Class getClassPropertyTypeForSetter(Class type, String name) {

    if (name.indexOf('.') > -1) {
      StringTokenizer parser = new StringTokenizer(name, ".");
      while (parser.hasMoreTokens()) {
        name = parser.nextToken();
        if(Map.class.isAssignableFrom(type)){// Map found
        	// Sets typeHandler to unknown
        	// any other subproperties are unknown so return
        	return Object.class; 
        }
        type = ClassInfo.getInstance(type).getSetterType(name);
      }
    } else {
      type = ClassInfo.getInstance(type).getSetterType(name);
    }

    return type;
  }

> ProbeExceptions with complex beans
> ----------------------------------
>
>          Key: IBATIS-45
>          URL: http://issues.apache.org/jira/browse/IBATIS-45
>      Project: iBatis for Java
>         Type: Bug
>   Components: SQL Maps
>     Versions: 2.0.8, 2.0.9
>  Environment: XP Pro; jdk 1.4.2
>     Reporter: S Boyd
>     Assignee: Clinton Begin
>      Fix For: 2.1.0

>
> When I create a resultMap that uses a complex bean that contains an
> associated Map, a ProbeException is thrown in two places when I 
> attempt to populate the map from the resultset using object
> graph navigation.
> For example:
> public class Account{
>    String id;
>    Map demographics;
>    // setters/getters left out
> }
> <resultMap id="accountResult" class="Account">
>  <result property="id"                   column="id"                        />
>  <result property="demographics.address" column="address" javaType="string" />
>  <result property="demographics.city"    column="city"    javaType="string" />
>  <result property="demographics.state"   column="state"                     />
> </resultMap>
> The two places that ibatis will fail is during the sqlmap parsing phase where it uses introspection on the result properties _if_ the javaType is not specified.  So in the resultMap above, "demographics.state" will generate a ProbeException because ibatis cannot determine what type "state" is.  Of course, it is not known until runtime because the value is stored in the Map "demographics".  Instead of a ProbeException, I think it should assign to the property the UnknownTypeHandler or something similar.  For now, the current workaround would be to include the javaType attribute.  
> Now, the second and more important place where the ProbeException is thrown is during the population of the object after the query is executed.  Since the parent class is a java bean, the GenericProbe.setObject() method uses the JavaBeanProbe.setObject() which tries to force "demographics" to have a g/setter methods for all three properties instead of just using Map.get() and Map.set().  Now, if the ComplexBeanProbe.setObject() is used, then everything works as expected.
> Thanks,
> Stephen

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira