Incorrect type of SQLServer column for Java 'float' field

Description

When mapping a Java field of type 'float' to a SQLServer table, the corresponding database column is created with type 'float', which is not correct as SQL Server floats are double precision, while Java floats are simple precision.
The corresponding column should be created with type "real".

Activity

Brett MeyerJuly 8, 2014 at 3:11 PM

Bulk rejecting stale issues. If this is still a legitimate issue on ORM 4, feel free to comment and attach a test case. I'll address responses case-by-case. Thanks!

Brett MeyerApril 7, 2014 at 5:45 PM

In an effort to clean up, in bulk, tickets that are most likely out of date, we're transitioning all ORM 3 tickets to an "Awaiting Test Case" state. Please see http://in.relation.to/Bloggers/HibernateORMJIRAPoliciesAndCleanUpTactics for more information.

If this is still a legitimate bug in ORM 4, please provide either a test case that reproduces it or enough detail (entities, mappings, snippets, etc.) to show that it still fails on 4. If nothing is received within 3 months or so, we'll be automatically closing them.

Thank you!

Guillaume GrussenmeyerMay 23, 2008 at 11:50 AM

In order not to have Hibernate schema validation telling you your DB schema is invalid because "double" Java fields are mapped to "float" columns, one must also add the following registration in her custom dialect:

registerColumnTyp( Types.DOUBLE, "float" );

Else, Hibernate will complain that the double Java field is mapped to a "float" column while it should be mapped to a "double precision" one (although the column was created by Hibernate itself...).

Guillaume GrussenmeyerMay 21, 2008 at 7:43 PM

Hi Anthony,

concerning the fact that "every Entity using java Float fields must map to a "real" type field in the database", that's precisely what we're trying to achieve: not doing so will led to precision loss during database data reading (trying to stuff a double-precision data (db level) into a single-precision one (java level)).

If your database contains "float" fields, they should be mapped as "double" in Java. In that case, Hibernate will use JDBC DOUBLE type (as per org.hibernate.type.DoubleType), so there is no need to add another mapping.

Another solution is not to use any float Java fields and use doubles instead.

Anthony OgierMay 13, 2008 at 6:12 PM

Actually it doesn't seem to be enough ... finally I did like you, creating my own dialect, extending org.hibernate.dialect.SQLServerDialect and including that code into the constructor :

registerColumnType( Types.FLOAT, "real" );

But then, every Entity using java Float fields must map to a "real" type field in the database. Moreover, if the database contains "float" fields, then one must add a mapping to another java type ...

I'm not sure it's the good solution to handle SQL Server "real" type into hibernate...

Rejected

Details

Assignee

Reporter

Components

Affects versions

Priority

Created January 8, 2008 at 5:39 PM
Updated July 8, 2014 at 3:11 PM
Resolved July 8, 2014 at 3:11 PM

Flag notifications