10

I'm using Hibernate as our Object-Relational Mapping, with a custom dialect for an obscure database.

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

    @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:

        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?

DuncanKinnear
  • 4,563
  • 2
  • 34
  • 65

1 Answers1

13

OK, after downloading the Hibernate sources, and stepping thru them with the debugger in NetBeans, I discovered that the problem lay in the proprietary JDBC driver's ResultSet sub-class, not in Hibernate.

The getBigDecimal method was always returning a value with a scale of 0.

When I contacted the developer of the JDBC driver, he spotted the bug and fixed it.

DuncanKinnear
  • 4,563
  • 2
  • 34
  • 65
  • What database, and what JDBC driver/version? – Jan-Willem Gmelig Meyling Jul 24 '16 at 16:07
  • 3
    The 'database' is actually a proprietary RDBMS engine called 'Genesis' on top of Acucobol (now MicroFocus) Vision indexed files. The Driver is called 'Vortex'. Both the driver and the engine are written by [Trifox Inc](http://www.trifox.com/index.html) but sold/distributed by [MicroFocus](https://www.microfocus.com/media/data-sheet/acuxdbc_tcm6-1136.pdf) – DuncanKinnear Jul 24 '16 at 21:17