You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by steve dunning <sd...@gmail.com> on 2008/09/12 16:54:09 UTC

Re: Problems with Stored Procedure Null Output Parameters

I finally got a custom type handler working properly (see code below) but I
still contend there is a bug with output parameter mapping in IBatis for
null database values.  In MappedStatement.RetrieveOutputParameters:175
without a custom type handler it uses the UnknownTypeHandler to set the
dataBaseValue object which then blows up in line 178 when it goes to call
SetOutputParameter. I don't really have the time right now to see exactly
why the Set cannot handle the DBNull type as I saw that alot of reflection
and dynamic method instantiation is used for setting values and it would
take me a while to figure out how it works.

   class DbNullTypeHandler : ITypeHandlerCallback
   {

      public void SetParameter(IParameterSetter setter, object parameter)
      {
         if (parameter != null)
         {
            if (parameter.Equals(DateTime.MinValue))
            {
               setter.Value = System.DBNull.Value;
            }
            else
            {
               setter.Value = parameter;
            }
         }
      }

      public object GetResult(IResultGetter getter)
      {
         if (getter.Value.Equals(System.DBNull.Value))
         {
            return NullValue;
         }
         else
         {
            return getter.Value;
         }
      }

      public object ValueOf(string nullValue)
      {
         return nullValue;
      }

      public object NullValue
      {
         get {return null; }
      }
   }


-- Original Message --

I am using a parameter class to encapsulate the input and output parameters
for an Oracle stored procedure that I am calling. When the stored proc
returns data for all of the Output parameters all is well, however, when
null values are returned in any of the parameters, well, that is when things
fall apart. It seems that the problem lies somewhere when converting the
System.DBNull value that is coming back from the database. A
System.InvalidCastException is thrown for any parameter that contains a
null.

I found the following JIRA entry
https://issues.apache.org/jira/browse/IBATISNET-247 that seemed to describe
the problem that I am encountering.  I thought, no problem I will just
create a custom type handler to manually convert to the right type.  After
reading many mail group threads and much experimentation I cannot seem to
get that working either.  Using the type handler then causes valid return
parameters to fail with cast exceptions.

*Any guidance or suggestions would be greatly appreciated!*

<< Remainder of Original Message Clipped >>