【问题标题】:hibernate and dates休眠和日期
【发布时间】:2012-03-15 12:32:28
【问题描述】:

我想使用 hibernate 获取开始日期和结束日期之间的记录。像,

id     startDate                 endDate
15     2011-01-05 05:05:10   2011-05-01 09:05:10 
37     2010-03-01 05:06:10   2010-06-01 09:07:10
49     2005-01-05 03:03:03   2005-05-01 08:08:08                  

我想在提供 startDate=2011-01-05 05:05:10 和 endDate=2011-05-01 09:05:10 时检索 15

我想在提供 startDate=2010-03-01 05:06:10 和 endDate=2010-06-01 09:07:10 时检索 37

谁能告诉我如何使用休眠?我尝试使用 between 子句但没有奏效。

【问题讨论】:

    标签: hibernate timestamp date


    【解决方案1】:

    您尝试使用什么标准?如果 startDate 和 endDate 都需要匹配要返回的行,那么您可以尝试使用以下限制:

    Restrictions.and(Restrictions.eq("startDate",startDateValue),Restrictions.eq("endDate", endDateValue))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-23
      • 2011-04-08
      • 2021-04-29
      • 1970-01-01
      • 2011-08-13
      • 2011-10-18
      相关资源
      最近更新 更多