Hibernate: Found: float, expected: double precision
Asked Answered
O

8

11

I have a problem with the mapping of Oracle Float double precision datatype to Java Double datatype. The hibernate schema validator seems to fail when the Java Double datatype is used.

org.hibernate.HibernateException: Wrong column type in DB.TABLE for column amount. Found: float, expected: double precision

The only way to avoid this is to disable schema validation and hope the schema is in sync with the app about to run. It must be fixed before it goes out to production.

App's evironment:
- Grails 1.2.1
- Hibernate-core 3.3.1.GA
- Oracle 10g

Oulu answered 26/3, 2010 at 16:36 Comment(4)
Could you show how you actually map this column? Btw by noting that you are in the last minutes before going to production, you just make sure to get witty remarks about your sloppiness to test your app in due time :-)Sandberg
Haha :) Don't worry, I'm not sloppy when it comes to production stuff. It won't goes out as long as it's not fixed. Anyway, it's a bug one of my co-worker encoutered and I'm simply trying to help him. Nice remark though :)Oulu
I edited my question according to your suggestion. Thx.Oulu
I'm afraid you're heading wrong way here. Oracle SQL does not any datatype like double or float. The only allowed numeric datatype for column is NUMBER. You can call PL/SQL procedures with parameters of type BINARY_DOUBLE, but this is something different, this datatype can not be stored in the database. If you want to be safe allays map Oracle's NUMBER (as its subtypes) to Java's BigDecimal.Paternoster
K
5

Need more info. The table is Double? I'm not familiar with Oracle, but is that a floating point type? What java.sql.Types type does it translate to? You can see the java.sql.Types to database type mapping in the dialect class for your database. In this case it is org.hibernate.dialect.Oracle10gDialect (which extends 9i and 8i). Looks like you have

registerColumnType( Types.DOUBLE, "double precision" );

So, the table needs to be defined as double precision, and the java class needs to be defined as something that will map to Types.Double, usually double.

From the error message, it looks like your table is defined as float which would use this mapping

registerColumnType( Types.FLOAT, "float" );

for which the expected java type would be something that maps to Types.FLOAT, usually float; a single precision value.

The easiest thing to do is either change your table or java class to match. Alternately, you can specify a user type that would map a single precision value to a double precision value; I can't think of why you would really want to do that, but maybe if you didn't have control over both the class and the table, which is quite rare, I would think.

hth.

Katti answered 26/3, 2010 at 16:51 Comment(0)
M
14

Unless you define a column type as double precision in DDL file, Oracle will convert it to float column type. So you need to register double as float column type in dialect class.

public class Oracle10gDialectExtended extends Oracle10gDialect {

    public Oracle10gDialectExtended() {
        super();
        registerColumnType(Types.DOUBLE, "float");
    }
}

Finally register Oracle10gDialectExtended in Hibernate/JPA configuration as hibernate.dialect.

Mudlark answered 7/11, 2012 at 14:48 Comment(1)
It didn't worked by adding the Oracle10gDialectExtended class in hibernate.cfg.xml file: <property name="hibernate.dialect">Oracle10gDialectExtended</property>Yu
K
5

Need more info. The table is Double? I'm not familiar with Oracle, but is that a floating point type? What java.sql.Types type does it translate to? You can see the java.sql.Types to database type mapping in the dialect class for your database. In this case it is org.hibernate.dialect.Oracle10gDialect (which extends 9i and 8i). Looks like you have

registerColumnType( Types.DOUBLE, "double precision" );

So, the table needs to be defined as double precision, and the java class needs to be defined as something that will map to Types.Double, usually double.

From the error message, it looks like your table is defined as float which would use this mapping

registerColumnType( Types.FLOAT, "float" );

for which the expected java type would be something that maps to Types.FLOAT, usually float; a single precision value.

The easiest thing to do is either change your table or java class to match. Alternately, you can specify a user type that would map a single precision value to a double precision value; I can't think of why you would really want to do that, but maybe if you didn't have control over both the class and the table, which is quite rare, I would think.

hth.

Katti answered 26/3, 2010 at 16:51 Comment(0)
D
5

If you are using Annotation method, you need to declare column type as below for the field.

@Column(name = "PERFORMANCE", columnDefinition = "FLOAT(5,2)")
private double performance;
Denney answered 14/7, 2015 at 13:43 Comment(0)
F
2

We had the same issue. We solved it by making sure to explicity set the column type in the mapping, like this:

<property name="performance" type="double">
  <column name="PERFORMANCE" sql-type="float" />
</property>
Fleischer answered 18/8, 2010 at 12:39 Comment(0)
B
1

application.properties

hibernate.dialect=com.test.config.Oracle10gDialectExtended

create class

package com.test.config;

import java.sql.Types;

import org.hibernate.dialect.Oracle10gDialect;

public class Oracle10gDialectExtended extends Oracle10gDialect {

    public Oracle10gDialectExtended() {
        registerColumnType(Types.DOUBLE, "float");
    }
}
Bregenz answered 5/6, 2019 at 9:32 Comment(0)
P
0

I had a case where my Oracle column type was NUMBER and the Java type was double.

Finally traced that it was down to settings

<property name="hbm2ddl.auto">validate</property>

just changed it to

<property name="hbm2ddl.auto">update</property>

and everything worked!

Penman answered 26/6, 2012 at 17:30 Comment(0)
Y
0

After lots of research and tries i found the solution of it. For Grails domain we can fix this problem by adding the sqlType as "float" for validation mode.

In Result.groovy

class Result{
    Double discount

    static mapping = {
        discount column: "discount", sqlType: "float"
    }

    static constraints = {
        discount(nullable: true)
    }
}

So it will remove the error in validation mode.

Yu answered 19/12, 2019 at 9:55 Comment(0)
E
-1

I had this issue when migrating a jboss 4/hibernate 3 app to as7/hibernate4. Problem solved by Rob Keilty's suggestion of changing hbm2ddl.auto from validate to update without having to change legacy code.

Eulogist answered 18/8, 2013 at 22:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.