休眠:发现:浮点数,预期:双精度 [英] Hibernate: Found: float, expected: double precision

查看:23
本文介绍了休眠:发现:浮点数,预期:双精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将 Oracle Float 双精度数据类型映射到 Java Double 数据类型时遇到问题.使用 Java Double 数据类型时,休眠模式验证器似乎失败.

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.

应用程序的环境:
- Grails 1.2.1
- 休眠核心 3.3.1.GA
- 甲骨文 10g

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

推荐答案

需要更多信息.桌子是双人的?我不熟悉 Oracle,但这是浮点类型吗?它转换为什么 java.sql.Types 类型?您可以在数据库的方言类中看到 java.sql.Types 到数据库类型的映射.在这种情况下,它是 org.hibernate.dialect.Oracle10gDialect(它扩展了 9i 和 8i).看起来你有

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" );

所以,表需要定义为double precision,java类需要定义为会映射到Types.Double的东西,通常是double.

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.

从错误消息来看,您的表似乎被定义为 float 将使用此映射

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

registerColumnType( Types.FLOAT, "float" );

预期的java类型将映射到Types.FLOAT,通常是float;单个精度值.

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

最简单的方法是更改​​您的表或 java 类以匹配.或者,您可以指定将单精度值映射到双精度值的用户类型;我想不通你为什么真的想这样做,但也许如果你不能控制课堂和桌子,我认为这是非常罕见的.

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.

这篇关于休眠:发现:浮点数,预期:双精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆