-->
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: problems querrying floats
PostPosted: Fri May 12, 2006 10:41 am 
Newbie

Joined: Tue Feb 21, 2006 10:34 am
Posts: 7
I am using hibernate v3.1 and MySQL4 on linux. I have come to a problem with querrying/comparing floats.

A 3rd party component has put a value, for example 4.4 into table with float column with defined precision (FLOAT(4,2)). The DB will not store the float exactly as 4.4, the float is always stored in system dependent format (probably as 4.400000001 or 4.3999999999). By running a general querry I get proper result:
Code:
select * from ttt;

score
4.4

However if I explicitely ask for the value with WHERE caluse I get nothing:
Code:
select * from ttt where score=4.4;

Empty set

More of this issue can be found in MySQL documentation http://dev.mysql.com/doc/refman/4.1/en/problems-with-float.html

In simple it can be handled by round construct
Code:
select * from ttt where round(score,2)=round(4.4,2);

score
4.4

I hoped I will handle this problem by specifying precision and scale attributes in Hibernate mapping file (<property name="score" column="`score`" type="float" not-null="false" precision="4" scale="2"/>) and then create Criterion object like "Restrictions.eq("score", new Float(4.4))".
But there is no visible effect on querry. With or without precision and scale attributes the querry created by Criteria class looks always the same (score=4.4).

I am looking for some way how to force hibernate to use round function in WHERE clause or any similar method when specifing the filter criteria for a column. Can anyone help me? Any idea what to do? 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.  [ 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.