You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by "cristian manea (JIRA)" <ib...@incubator.apache.org> on 2007/07/31 16:35:52 UTC

[jira] Commented: (IBATISNET-221) InvalidCastException while getting object out of the cache

    [ https://issues.apache.org/jira/browse/IBATISNET-221?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12516705 ] 

cristian manea commented on IBATISNET-221:
------------------------------------------

Hello. This is the workaround that I have used for this (although I think that in version 1.6.1 there is no more need for this, it was solved):

        public override ResourceDataCarrier Read(ResourceDataCarrier obj)
        {
            System.Object objreturn;
            objreturn = Mapper().QueryForObject<object>("SelectResource", obj);
            if (objreturn == null) 
                return (null);
             
            return ((ResourceDataCarrier) objreturn);
        }

Hope this will help you.

Regards.

www.atypiq.ro

> 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.