-->
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.  [ 5 posts ] 
Author Message
 Post subject: Criteria Projecton / avg returns INTEGER
PostPosted: Sat Feb 26, 2005 2:42 pm 
Newbie

Joined: Sat Feb 26, 2005 2:33 pm
Posts: 4
Hi,

I have a table with an integer column "value". When using the Criteria queries to get the averange of some rows an INTEGER is returend where I would expect a DOUBLE or FLOAT. How can I get the double/float value? Do I have to make the column of type DOUBLE/FLOAT ?

Currently I'm using this code with Hibernate 3.0b4
Object o = criteria.setProjection( Projections.avg("value")).uniqueResult();

Thanks for any hints. Axel


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 26, 2005 4:05 pm 
Regular
Regular

Joined: Thu Dec 18, 2003 2:14 am
Posts: 103
Location: Brooklyn, NY
Can you get this to work in pure SQL? That will give you your hint.

I have a suspicion that SQL aggregate queries return in the type of the column, but someone else will have to verify or refute this. I'm not sure.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 26, 2005 8:50 pm 
Newbie

Joined: Sat Feb 26, 2005 2:33 pm
Posts: 4
from the log I can see that this SQL is created:
select avg(this_.value) as y0_ from [...]

When I use the command line SQL interface and paste the query, I get the result "3.5000" for the 2 matching items with "3" and "4" as value. I will test the same pure SQL query in Hibernate tomorrow to see what happen there.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 26, 2005 8:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This was a bug that has already been fixed for 3.0 final.


Top
 Profile  
 
 Post subject: Does the bug happens on the 2.x versions too?
PostPosted: Thu Apr 20, 2006 9:36 pm 
Beginner
Beginner

Joined: Fri Feb 06, 2004 6:59 am
Posts: 36
Location: S
Hello Gavin, I am using an old version of hibernate. 2.1.6 I think.

Does this bug happens with it too?

I see that it returns an array of Objects[] and containing several Float, for each avg(field) on the select statement.

My question is....

Is there any way to make it return an array of BigDecimal?

Thanks in advance...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.