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.  [ 4 posts ] 
Author Message
 Post subject: float rounding on MySQL
PostPosted: Wed Aug 27, 2003 2:56 am 
Newbie

Joined: Wed Aug 27, 2003 2:43 am
Posts: 19
Location: Paris
Hello,

I have a float rounding problem with Hibernate which only appears with MySQL.

The problem is: when an object contains a float data type, values inserted in mysql are rounded to their closest integers.

For instance:

<class name="com.kertel.kercash.serialization.TarifUsingAppel" table="tarif">

....

<property name="amount" type="float" column="tari_montant" />

...

</class>

corresponding to this class:

public class TarifUsingAppel extends Tarif {
...
}

and

public class Tarif {
private float amount;
....
}


Saving such a class, into the table:

CREATE TABLE tarif (
tari_id int(11) NOT NULL default '0',
tari_montant float NOT NULL default '0',
PRIMARY KEY (tari_id)
) TYPE=MyISAM;

always transforms my floats into integers.

Browsing the net i found this on the mysql jdbc driver:

http://www.mysql.com/documentation/conn ... #id2802892

I use:

mysql version: MySQL 3.23.49-max-n
hibernate 2.0.2
jdbc drver: mysql-connector-java-2.0.14-bin.jar

Thank you for your ideas,
Adrian.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2003 9:35 am 
Newbie

Joined: Tue Aug 26, 2003 9:59 am
Posts: 19
Location: Atlanta, GA
First, I would check if this rounding is happening when you use straight SQL to insert . Second, you may want to look at this.

_________________
Bill Siggelkow


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2003 12:15 pm 
Newbie

Joined: Wed Aug 27, 2003 2:43 am
Posts: 19
Location: Paris
Sorry, it was an error somewhere in my application it has nothing to do with Hibernate nor with the MySQL jdbc driver.

I could have sworn I saw this behavior several times (and I ignored them as MySQL is my test database) but I guess it's the same error that repeated several times.

Thanks for the URL, anyway; I also tried the direct JDBC insert, it worked: float in mysql accepts decimals so there's no problem there.

Best regards,
Adrian.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2008 11:33 pm 
Newbie

Joined: Tue Dec 16, 2008 11:22 pm
Posts: 1
No, It actually do happens even when there is problem with SQL base .So you cann't consider it as your fault only




















____________________________________________________
SMS


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