-->
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: BigDecimal column mapping for Custom Dialect
PostPosted: Thu Feb 06, 2014 4:04 pm 
Newbie

Joined: Tue Sep 08, 2009 7:38 pm
Posts: 6
I'm using Hibernate as our JPA Object-Relational Mapping, with a custom dialect for an obscure database.

The Entity I'm retrieving from this database has a column thus:

Code:
        @Column(name = "GROSS_WEIGHT", precision = 9, scale = 3)
        private BigDecimal grossWeight;


The database has this column defined as numeric with a precision of 9 and a scale of 3.

I can see the SQL that Hibernate generates to retrieve the data, and when I perform the same Query using the database query tool it returns '9.68' for the GROSS_WEIGHT column.

However, in the Entity that is retrieved by Hibernate, the 'grossWeight' field contains the value '10', with a scale of 0 and precision of 2!

in the custom dialect class I'm using I've tried overriding the following Column Types:

Code:
            registerColumnType( Types.DECIMAL, "numeric($p,$s)" );
            registerColumnType( Types.DOUBLE, "numeric($p,$s)" );
            registerColumnType( Types.NUMERIC, "numeric($p,$s)" );


but it stills returns just the (rounded) whole number.

This has worked elsewhere in the application where we retrieve objects from Postgres using the Postgres dialect.

Any idea what I should be doing in the dialect so I can get Hibernate to correctly set the precision/scale of the BigDecimal retrieved?


Top
 Profile  
 
 Post subject: Re: BigDecimal column mapping for Custom Dialect
PostPosted: Wed Feb 12, 2014 8:08 pm 
Newbie

Joined: Tue Sep 08, 2009 7:38 pm
Posts: 6
Never mind.

After downloading the sources and stepping thru the Hibernate Loader in the debugger, I found that the problem was in the 'getBigDecimal' method of the proprietary JDBC driver's sub-class of 'ResultSet'.

Contacted the developer and he confirmed that it was defaulting to a scale of zero.


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.