I started playing with iBATIS few days ago and today I came across the problem 
that I can't get around so far. 

The problem: I modified the Person example in the iBATIS' tutorial to call 
stored procedure (MSSQL 2000) to get the list of people instead of using a 
SELECT. It looks like that: 

<parameterMap id="PersonGetById-params">
        <parameter property="Id" column="PersonId"/>
</parameterMap>

<procedure id="Select" parameterMap="PersonGetById-params" 
resultMap="SelectResult">
        PersonGetById
</procedure>

I tested it and the following statement works fine:
       return Mapper ().QueryForList ("Select", 1 );

However, the next one using a null as a parameter fails (with 
NullReferenceException, see full stack trace below):
        return Mapper ().QueryForList ("Select", null );

I looked at the iBATIS source and it seems like there's a problem in 
\IBatisNet.DataMapper\Configuration\ParameterMapping\ParameterMap.cs. 
SetParameter method has the following code in it (which fails when 
parameterValue is null)

if ( parameterValue.GetType() != typeof(string) && 
     parameterValue.GetType() != typeof(Guid) &&
     parameterValue.GetType() != typeof(Decimal) &&
     parameterValue.GetType() != typeof(DateTime) &&
     !parameterValue.GetType().IsPrimitive)
{
 

I wonder what is that I am doing wrong and is there a way to pass a null 
parameter value to a stored procedure or do I always have to use null 
substitute? 

Thanks!

PS Full exception text: 

Server Error in '/ibatistutorial' Application. 
________________________________________
Object reference not set to an instance of an object. 
Description: An unhandled exception occurred during the execution of the 
current web request. Please review the stack trace for more information about 
the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to 
an instance of an object.

Source Error: 

Line 15:                public IList SelectAll ()
Line 16:                {
Line 17:                        return Mapper ().QueryForList ("Select", null );
Line 18:                }
Line 19: 

Source File: c:\orms\ibatis\tutorial\model\personhelper.cs    Line: 17 

Stack Trace: 

[NullReferenceException: Object reference not set to an instance of an object.]
   
IBatisNet.DataMapper.Configuration.ParameterMapping.ParameterMap.SetParameter(ParameterProperty
 mapping, IDataParameter dataParameter, Object parameterValue)
   
IBatisNet.DataMapper.Commands.DefaultPreparedCommand.ApplyParameterMap(IDalSession
 session, IDbCommand command, RequestScope request, IStatement statement, 
Object parameterObject)
   IBatisNet.DataMapper.Commands.DefaultPreparedCommand.Create(RequestScope 
request, IDalSession session, IStatement statement, Object parameterObject)
   
IBatisNet.DataMapper.MappedStatements.MappedStatement.RunQueryForList(RequestScope
 request, IDalSession session, Object parameterObject, Int32 skipResults, Int32 
maxResults, RowDelegate rowDelegate)
   
IBatisNet.DataMapper.MappedStatements.MappedStatement.ExecuteQueryForList(IDalSession
 session, Object parameterObject, Int32 skipResults, Int32 maxResults)
   
IBatisNet.DataMapper.MappedStatements.MappedStatement.ExecuteQueryForList(IDalSession
 session, Object parameterObject)
   IBatisNet.DataMapper.SqlMapper.QueryForList(String statementName, Object 
parameterObject)
   iBatisTutorial.Model.PersonHelper.SelectAll() in 
c:\orms\ibatis\tutorial\model\personhelper.cs:17
   iBatisTutorial.Web.Forms.PersonPage.List_Load() in 
c:\orms\ibatis\tutorial\webview\forms\person.aspx.cs:24
   iBatisTutorial.Web.Forms.PersonPage.Page_Load(Object sender, EventArgs e) in 
c:\orms\ibatis\tutorial\webview\forms\person.aspx.cs:88
   System.Web.UI.Control.OnLoad(EventArgs e)
   System.Web.UI.Control.LoadRecursive()
   System.Web.UI.Page.ProcessRequestMain()

________________________________________
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET 
Version:1.1.4322.2032

Thanks,

Stas Antropov
STA Group
333 W. Wacker Dr, Suite 850
Chicago, IL 60606
Office/Cell: 847-331-7528
[EMAIL PROTECTED]

Reply via email to