-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Exception using Futures with IQuery
PostPosted: Fri Oct 22, 2010 3:54 pm 
Newbie

Joined: Thu Sep 30, 2010 4:06 pm
Posts: 5
Hello,

I am writing custom paging in an ASP.NET application using NHibernate for data access. I am making use of IQuery and Future, FutureValue, SetFirstResult, and SetMaxResult in the paging implementation. I have two queries: one to fetch a page of data which match certain criteria and the other to fetch the count of all data with that criteria. I have verified using the SQL Server Profiler that the SQL is executed successfully, however, I get the following exception:

Code:
[ArgumentException: The value "28" is not of type "System.Int32" and cannot be used in this generic collection.
Parameter name: value]
   System.ThrowHelper.ThrowWrongValueTypeArgumentException(Object value, Type targetType) +122
   System.Collections.Generic.List`1.VerifyValueType(Object value) +2533366
   System.Collections.Generic.List`1.System.Collections.IList.Add(Object item) +15
   NHibernate.Impl.MultiQueryImpl.DoList() +1505

[HibernateException: Failed to execute multi query: ...


Here is the core piece of code:

Code:
            ...
            IQuery q = Session.CreateQuery(query);

            int firstResult = pageIndex * pageSize;
            q.SetFirstResult(firstResult);
            q.SetMaxResults(pageSize);

            IEnumerable<DataSourceBO> retVal = q.Future<DataSourceBO>();

            IQuery qCount = Session.CreateQuery(countQuery);

            var futureValue = qCount.FutureValue<int>();

            totalCount = futureValue.Value;//exception occurs here

            return retVal.ToList();


Anyone have an idea what may be causing the exception? Thanks in advance for your help.


Top
 Profile  
 
 Post subject: Re: Exception using Futures with IQuery
PostPosted: Fri Oct 22, 2010 4:29 pm 
Newbie

Joined: Thu Sep 30, 2010 4:06 pm
Posts: 5
I think I figured this one out. I updated my count HQL from:

select count(*) from...

To:

select cast(count(*) as int) from...

I no longer get the exception.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.