-->
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.  [ 1 post ] 
Author Message
 Post subject: result of division is not a floating point
PostPosted: Fri Apr 30, 2010 8:43 am 
Newbie

Joined: Thu Jun 25, 2009 7:22 am
Posts: 9
How can I tell hibernate to return a floating point 0.5 for this query?
Code:
select distinct (1 / 2) from Dataset


But instead of 0.5 hibernate returns 0 for this query, although the generated MySQL query
Code:
select distinct 1/2 as col_0_0_ from Dataset dataset0_

returns already a floating point. So it seems that hibernate converts the floating point value into an integer before returning to the user and the question is how to get rid of that.

A unpleasant workaround could be the casting to a string:
Code:
select distinct cast((1 / 2) as string) from Dataset

Then hibernate returns the string "0.5000" and we only have to cast it back to double or float. But this is really a hack IMO. I also tried to cast the value to float/double within the query but then hibernate constructs a query that MySQL does not understand, i.e. it contains "cast(... as float)".


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

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.