在Hibernate查询中,setTime(...)和setTimestamp(...)有什么区别? [英] What's the difference between setTime(...) and setTimestamp(...) in Hibernate Query?

查看:353
本文介绍了在Hibernate查询中,setTime(...)和setTimestamp(...)有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么setTime方法的行为与setDate完全相同,没有时间日期,或者在2014-07-01 13:21:01设置时间2014-07-01 00:00:00? !?!



setTime是否被弃用?
我应该使用setTimestamp吗?

解决方案

Oracle以外的数据库实际上可以区分三种不同的数据类型:
$ b $ ul
$ DATE 只有日期,没有时间

  • TIME 仅限一天中的时间,无日期

  • TIMESTAMP 两者,日期&安培;时间。



  • JDBC尝试抽象标准SQL概念,上述三种数据类型由ANSI SQL定义,因此JDBC需要支持它们。 p>

    由于Oracle的日期总是包含时间,所以必须使用 setTimestamp()否则将数据存储在数据库中时会丢失时间。


    I wonder why the setTime method behaves exactly like setDate, date without time, or instead to set the time on 2014-07-01 13:21:01 it is set on 2014-07-01 00:00:00 ?!?!

    Is setTime deprecated? Should I use setTimestamp???

    解决方案

    Databases other than Oracle actually do distinguish between three different datatypes:

    • DATE only date, no time
    • TIME only time of the day, no date
    • TIMESTAMP both, date & time.

    JDBC tries to abstract standard SQL concepts and the above three datatypes are defined by ANSI SQL and thus JDBC needs to support them.

    As Oracle's date always includes the time, you have to use setTimestamp() otherwise the time is lost when you store it in the database.

    这篇关于在Hibernate查询中,setTime(...)和setTimestamp(...)有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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