Hibernate标准中日期之间的限制 [英] Restrictions Between for Date in Hibernate Criteria
问题描述
您好,我在我的示例中使用了hibernate。对于Bean Table Audit Trial,我想在包含upper&下限。
我的代码如下
Hello I am using hibernate in my example.For bean Table Audit Trial I want to fetch audit trial between a date range with inclusion of upper & lower limits. My code is like below
Criteria criteria = session.createCriteria(AuditTrail.class);
criteria.add(Restrictions.between("auditDate", sDate, eDate));
我的开始日期是 25/11/2010
。并且结束日期是 25/05/2011
。但它只会将结果提供给 24/05/2011
它不执行包容性搜索。任何其他方式来执行此操作。
我正在使用SQL服务器。
My starting date is 25/11/2010
. and end date is 25/05/2011
.But it is only giving the result up to 24/05/2011
.It is not performing inclusive search.Any other way to do this.
I am using SQL server.
推荐答案
我假设您的auditDate实际上是一个时间戳。如果是这种情况,那么这是正常的,因为25/05/2011意味着25/05/2011在0点(在早上)。因此,当然,2011年5月25日的每一行都有一个审计时间戳,早上0点以后。
I assume your auditDate is in fact a timestamp. If it's the case, then this is normal, because 25/05/2011 means 25/05/2011 at 0 o'clock (in the morning). So, of course, every row having an audit timestamp in the date 25/05/2011 is after 0 o'clock in the morning.
我会将1天添加到结束日期,并使用 auditDate> = sDate and auditDate< EDATE
。
I would add 1 day to your end date, and use auditDate >= sDate and auditDate < eDate
.
criteria.add(Restrictions.ge("auditDate", sDate));
criteria.add(Restrictions.lt("auditDate", eDate));
这篇关于Hibernate标准中日期之间的限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!