-->
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: class cast exception.
PostPosted: Thu Aug 05, 2010 4:24 am 
Newbie

Joined: Thu Aug 05, 2010 2:03 am
Posts: 1
I am upgrading hibernate 3.1.2 to 3.5.4.
In query i used count() function and add addScalar() as Integer. In older ver. i get int value but after upgrading i get long value and throw class cast exception.

code are:

StringBuilder query = new StringBuilder(
"select count(distinct s.student_id) as tot from teacher t inner join student s p on s.student_id=t.student_id");
Query q = getQuery1(query, organization, accessiblePortfolio, true, fetchExportControl, type,
false, filterHelper);
((SQLQuery) q).addScalar("tot", Hibernate.INTEGER);
return (Integer) q.uniqueResult();

Please help me.
Thanks.


Top
 Profile  
 
 Post subject: Re: class cast exception.
PostPosted: Thu Aug 05, 2010 10:51 am 
Beginner
Beginner

Joined: Thu Feb 08, 2007 10:40 am
Posts: 46
try this:
Code:
Number result = (Number)q.uniqueResult();
return Integer.valueOf(result.intValue());


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.