hibernate.hbm2ddl.auto=validate throws errors "Wrong column type in xxx for column xxx. Found: float, expected: double precision" in Oracle database.

Description

When a java "double" type is defined in an entity class, a "float" type column is created in oracle database when setting hibernate.hbm2ddl.auto=create(or update).

The java "double" type is interpreted as "double precision" in the table creation script by Hibernate. For example,

a table create script could look like:

CREATE TABLE MyUser (
user_id NUMBER(9) PRIMARY KEY,
height double precision NOT NULL)

It generates a column "height" of type "float".

The same table creation script generates type "double" in mysql database.

It appears that oracle database doesn't have a data type "double". It has "BINARY_DOUBLE" instead.

In addition, after a double type being created as "float" in the database, if setting the hibernate.hbm2ddl.auto=validate, it throws error:

Caused by: org.hibernate.HibernateException: Wrong column type in xxx for column xxx. Found: float, expected: double precision
at org.hibernate.mapping.Table.validateColumns(Table.java:284)
at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1129)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:139)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:360)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1340)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:670)

Strong Liu has suggested to change the default type mapping in org.hibernate.dialect.Oracle8iDialect
from
registerColumnType( Types.DOUBLE, "double precision" );
to
registerColumnType( Types.DOUBLE, "float" );

I have tried to create my own dialect to override the default behavior.

For example:

import org.hibernate.dialect.Oracle10gDialect;
import java.sql.Types;
public class Oracle11gDialectExt extends Oracle10gDialect {

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

}

And then set my own dialect in the persistence.xml, for example:
<property name="hibernate.dialect" value="jpa.test.hibernate.dialect.Oracle11gDialectExt" />

Then I don't see the error any more.

Environment

JBoss EAP5

Activity

Show:
Brett Meyer
November 19, 2013, 11:37 PM

, assigning to you since you were in the original discussion.

Steve Ebersole
October 27, 2015, 7:15 PM

This bug report does not indicate that the reported issue affects version 5.x. Versions prior to 5.x are no longer maintained. It would be a great help to the Hibernate team and community for someone to verify that the reported issue still affects version 5.x. If so, please add the 5.x version that you verified with to the list of affected-versions and attach the (preferably SSCCE) test case you used to do the verification to the report; from there the issues will be looked at during our triage meetings.

For details, see http://in.relation.to/2015/10/27/great-jira-cleanup-2015/

Steve Ebersole
October 28, 2015, 3:24 AM

As part of verifying that this issue affects 5.0, please just set the "Affects version". Leave the "verify-affects-5.0" label and leave the issue in "Awaiting Response" status; these are critical for us to be able to track these verifications and triage them. Thanks.

Cristian Manuel Vertiz Fernandez
September 27, 2017, 6:26 PM

I tested in version 5.1.10 and it happens

Assignee

Strong Liu

Reporter

Gary Hu

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure