我将Oracle Float双精度数据类型映射到Java Double数据类型存在问题。使用Java Double数据类型时,hibernate模式验证程序似乎失败。
org.hibernate.HibernateException:数据库中列的类型错误。表列数量。发现:float,expected:double precision
避免这种情况的唯一方法是禁用模式验证并希望模式与即将运行的应用程序同步。应用环境:
- Grails 1.2.1
- Hibernate -core 3.3.1.GA
- Oracle 10g
需要更多信息。桌子是Double?我不熟悉Oracle,但它是浮点类型吗?什么 java.sql.Types
类型转换为?您可以在数据库的dialect类中看到 java.sql.Types
到数据库类型映射。在这种情况下,它是 org.hibernate.dialect.Oracle10gDialect
(它扩展了9i和8i)。看起来像你有
registerColumnType(Types.DOUBLE,double precision);
所以,表格需要定义为 double precision
,并且需要将java类定义为映射到 Types.Double
,通常 double
。
从错误信息中看来,你的表格被定义为 float
,它将使用这个映射 p>
registerColumnType(Types.FLOAT,float);
其中预期的java类型将映射到 Types.FLOAT
,通常 float
;一个单一的精度值。
最简单的方法是更改您的表或Java类以匹配。或者,您可以指定将单个精度值映射到双精度值的用户类型;我想不出为什么你真的想这样做,但也许如果你对班级和表格都没有控制权,这很少见,我会想。
。
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
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.
这篇关于休眠:发现:浮动,预期:双精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!