[
https://issues.apache.org/jira/browse/IBATISNET-221?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12504480
]
Douglas M. Smith commented on IBATISNET-221:
--------------------------------------------
Here is a temporary work around:
//This method seems to return a strange iBatis error when CACHE is enabled and
the result is NULL.
return dataMapper.Instance().QueryForObject<MyObject>("MyQueryName", MyParams);
//This method seems to work with cache enabled.
return (MyObject)dataMapper.Instance().QueryForObject("MyQueryName", MyParams);
> InvalidCastException while getting object out of the cache
> ----------------------------------------------------------
>
> Key: IBATISNET-221
> URL: https://issues.apache.org/jira/browse/IBATISNET-221
> Project: iBatis for .NET
> Issue Type: Bug
> Components: DataMapper
> Affects Versions: DataMapper 1.6.1
> Environment: IBatis.net SVN, revision 527493, .Net 2.0
> Reporter: Rogelio J. Baucells
> Priority: Critical
>
> There is a problem in the implementation of
> CachingStatement::ExecuteQueryForObject for .Net2.0. The following scenario
> triggers the InvalidCastException:
> - Create a <ResultMap>, <procedure>, <parameterMap> and <cacheModel> for a
> select statement.
> - Invoke the statement with parameters that does not return any results
> - Invoke the same statement again
> The first invocation will store a NULL_OBJECT in the cache for this key
> (CacheModel::this[CacheKey key]), the second statement will retrieve the
> NULL_OBJECT from the cache and will cause the InvalidCastException at:
> obj = (T)this.Statement.CacheModel[cacheKey];
> Also the next statement will never be TRUE since obj is of type T:
> if ((object)obj == CacheModel.NULL_OBJECT)
> The solution for this problem would be declaring obj as object and casting to
> T at the time of returning from the method, something like:
> object obj = null;
> ...
> return (T)obj;
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.