休眠:发现:浮点数,预期:双精度
我在将 Oracle Float 双精度数据类型映射到 Java Double 数据类型时遇到问题。当使用 Java Double 数据类型时,hibernate 模式验证器似乎会失败。
org.hibernate.HibernateException: Wrong column type in DB.TABLE for column amount. Found: float, expected: double precision
避免这种情况的唯一方法是禁用架构验证并希望架构与即将运行的应用程序同步。在投入生产之前必须对其进行修复。
应用环境:
- Grails 1.2.1
- Hibernate核心3.3.1.GA
- 甲骨文10g
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
除非您在 DDL 文件中将列类型定义为双精度,否则 Oracle 会将其转换为浮点列类型。因此需要在方言类中将 double 注册为 float 列类型。
最后在 Hibernate/JPA 配置中将
Oracle10gDialectExtended
注册为hibernate.dialect
。Unless you define a column type as
double precision
in DDL file, Oracle will convert it tofloat
column type. So you need to register double as float column type in dialect class.Finally register
Oracle10gDialectExtended
in Hibernate/JPA configuration ashibernate.dialect
.需要更多信息。桌子是双人的?我对Oracle不熟悉,但那是浮点类型吗?它转换成什么 java.sql.Types 类型?您可以在数据库的方言类中看到
java.sql.Types
到数据库类型的映射。在本例中,它是 org.hibernate.dialect.Oracle10gDialect(它扩展了 9i 和 8i)。看起来你有所以,表需要定义为
双精度
,并且java类需要定义为映射到Types.Double
的东西,通常<代码>双。从错误消息来看,您的表似乎被定义为
float
,它将使用此映射,其中预期的 java 类型通常会映射到
Types.FLOAT
浮动
;单个精度值。最简单的方法是更改表或 java 类以匹配。或者,您可以指定将单精度值映射到双精度值的用户类型;我想不出为什么你真的想这样做,但也许如果你无法控制班级和桌子,我认为这是相当罕见的。
嗯。
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 thejava.sql.Types
to database type mapping in the dialect class for your database. In this case it isorg.hibernate.dialect.Oracle10gDialect
(which extends 9i and 8i). Looks like you haveSo, the table needs to be defined as
double precision
, and the java class needs to be defined as something that will map toTypes.Double
, usuallydouble
.From the error message, it looks like your table is defined as
float
which would use this mappingfor which the expected java type would be something that maps to
Types.FLOAT
, usuallyfloat
; 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.
如果您使用注释方法,则需要为字段声明列类型,如下所示。
If you are using Annotation method, you need to declare column type as below for the field.
我们有同样的问题。我们通过确保在映射中明确设置列类型来解决这个问题,如下所示:
We had the same issue. We solved it by making sure to explicity set the column type in the mapping, like this:
hibernate.dialect=com.test.config.Oracle10gDialectExtended
hibernate.dialect=com.test.config.Oracle10gDialectExtended
我遇到过这样的情况:我的 Oracle 列类型为
NUMBER
,而 Java 类型为double
。最后发现它是由于设置
只是将其更改为
一切正常!
I had a case where my Oracle column type was
NUMBER
and the Java type wasdouble
.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!
经过大量的研究和尝试,我找到了解决方案。对于 Grails 域,我们可以通过将 sqlType 添加为“float” 作为验证模式来解决此问题。
在 Result.groovy 中
,它会消除验证模式下的错误。
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
So it will remove the error in validation mode.
我在将 jboss 4/hibernate 3 应用程序迁移到 as7/hibernate4 时遇到了这个问题。 Rob Keilty 建议将 hbm2ddl.auto 从验证更改为更新,而无需更改旧代码,从而解决了问题。
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.