将 Oracle Date 与 Hibernate 结合使用时的日期/时间的 Java 类型 [英] Java type for date/time when using Oracle Date with Hibernate

查看:18
本文介绍了将 Oracle Date 与 Hibernate 结合使用时的日期/时间的 Java 类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个 Oracle 日期列.起初,在我们的 Java/Hibernate 类中,我们使用 java.sql.Date.这有效,但当我们保存时,它似乎没有在数据库中存储任何时间信息,所以我将 Java 数据类型更改为时间戳.现在我们得到这个错误:

We have a Oracle Date column. At first in our Java/Hibernate class we were using java.sql.Date. This worked but it didn't seem to store any time information in the database when we save so I changed the Java data type to Timestamp. Now we get this error:

springframework.beans.factory.BeanCreationException:使用名称创建 bean 时出错'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0'在类路径资源中定义[保证金服务域-config.xml]:bean初始化失败;嵌套异常是org.springframework.beans.factory.BeanCreationException: 创建 bean 时出错在类中定义的名称sessionFactory"路径资源 [m-service-domain-config.xml]:调用init方法失败;嵌套异常是org.hibernate.HibernateException:错误的列类型:CREATE_TS,预期:时间戳

springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.an notation.PersistenceExceptionTranslationPostProcessor#0' defined in class path resource [margin-service-domain -config.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreatio nException: Error creating bean with name 'sessionFactory' defined in class path resource [m-service-doma in-config.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Wrong column type: CREATE_TS, expected: timestamp

关于如何在保留时间部分的同时映射 Oracle Date 的任何想法?

Any ideas on how to map an Oracle Date while retaining the time portion?

更新:如果我使用 Oracle Timestamp 数据类型,我可以让它工作,但我不希望理想的精度水平.只需要基本的 Oracle Date.

Update: I can get it to work if I use the Oracle Timestamp data type but I don't want that level of precision ideally. Just want the basic Oracle Date.

推荐答案

不是直接的答案,但我会使用 Oracle TIMESTAMP 类型:

Not a direct answer but I'd use the Oracle TIMESTAMP type:

  • TIMESTAMP(小数秒_精度)年、月和日值日期,以及小时、分钟和第二个时间值,其中fractional_seconds_precision可选地指定数量小数部分的数字SECOND 日期时间字段,可以是0 到 9 范围内的数字.默认值为 6.例如,您指定TIMESTAMP 作为文字如下:

  • TIMESTAMP (fractional_seconds_ precision) Year, month, and day values of date, as well as hour, minute, and second values of time, where fractional_seconds_precision optionally specifies the number of digits in the fractional part of the SECOND datetime field and can be a number in the range 0 to 9. The default is 6. For example, you specify TIMESTAMP as a literal as follows:

TIMESTAMP'1997-01-31 09:26:50.124'

具有所需的fractional_second_precision.

这篇关于将 Oracle Date 与 Hibernate 结合使用时的日期/时间的 Java 类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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