-->
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: postgres dialect maps double to float8, rounds values
PostPosted: Thu Oct 15, 2009 9:40 pm 
Beginner
Beginner

Joined: Thu Jul 22, 2004 10:51 pm
Posts: 29
Location: sydney australia
Hi,

I've got a double which I'm trying to save to a postgres numeric column.

The value I'm trying to save is 151.33160591125488, and I've verified that this is in fact the argument being received by Hibernates internals pre-insert.

However the value in the database post insert is 151.331605911255, ie it's been rounded to 12dp.

I know my column is of the right scale, as it's an unrestricted numeric column and the following...
Code:
update tbl set col=151.33160591125488

...has the desired effect.

org.hibernate.dialect.PostgreSQLDialect:
Code:
    registerColumnType( Types.DOUBLE, "float8" );
    registerColumnType( Types.NUMERIC, "numeric($p, $s)" );

Code:
select cast (151.33160591125488 as float8);
=151.331605911255

therefore the default behavior for double is incorrect, and i need to get hibernate to use the numeric type before I'll get the expected behavior, but
Code:
    <property type="numeric" />

doesn't work, as "numeric" is not a hibernate type.

How do I get hibernate to save doubles properly?


Top
 Profile  
 
 Post subject: Re: postgres dialect maps double to float8, rounds values
PostPosted: Thu Oct 15, 2009 10:11 pm 
Beginner
Beginner

Joined: Thu Jul 22, 2004 10:51 pm
Posts: 29
Location: sydney australia
I've also tried
Code:
<property name="col">
   <column name="col" sql-type="numeric"/>
</property>
and
Code:
<property name="col" precision="30" scale="20" />
with no luck.


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.