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

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

问题描述

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


springframework.beans.factory.BeanCreationException:
创建名为
' org.springframework.dao.an
notation.PersistenceExceptionTranslationPostProcessor#0'
在类路径资源中定义
[margin-service-domain
-config.xml]:bean的初始化失败;嵌套异常是
org.springframework.beans.factory.BeanCreatio
nException:在
中定义的
名称'sessionFactory'创建bean时出错$ b path resource [m-service-doma
in-config.xml]:调用init
方法失败;嵌套异常是
org.hibernate.HibernateException:
错误的列类型:CREATE_TS,
expected:timestamp


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






更新:如果我使用Oracle Timestamp 数据类型,但我不希望这个级别的精度是理想的。只需要基本的Oracle Date

解决方案

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



  • TIMESTAMP(fractional_seconds_ precision) / strong>年份,月份和日期值
    的日期,以及小时,分钟和
    第二个时间值,其中
    fractional_seconds_precision
    可选地指定
    SECOND datetime字段的小数部分中的
    数字的数量,可以是
    数字范围为0到9.
    的默认值为6.例如,您将指定
    TIMESTAMP 作为文字,如下所示:

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



与所需的 fractional_second_precision


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: 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

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


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.

解决方案

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

  • 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'
    

with the desired fractional_second_precision.

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

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