HQL(休眠)时间戳范围匹配 [英] HQL(hibernate) timestamp range match

查看:205
本文介绍了HQL(休眠)时间戳范围匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I need to write a query to get an object between a range of time, currently the query looks like this:

我需要编写一个查询来获取一段时间内的对象, Timestamp from = ...
Timestamp to = ...

getHibernateTemplate()。find(from+ Person.class.getName()+ml where ml.lastModifiedOn> = + from.toString()+和m1.lastModifiedOn< =+ to.toString());

Timestamp from = ... Timestamp to = ... getHibernateTemplate().find("from " + Person.class.getName() + " ml where ml.lastModifiedOn>="+from.toString()+" and m1.lastModifiedOn<=" + to.toString());

然而,这并不适用于明显的原因。

However, this doesnot work for obvious reasons. How can I format the timestamp to be acceptable by the query.

推荐答案

你遗漏了单引号在你当前的查询中。以下内容应该可以工作:

You're missing single quotes in your current query. The following should work:

from Person ml where ml.lastModifiedOn 
between '2010-02-12 16:00:21.292' and '2010-02-12 23:00:21.292' 

请注意, t知道为什么你没有将 Date 实例传递给以下查询:

Note that I don't know why you're not passing Date instances to the following query:

from Person ml where ml.lastModifiedOn between :from and :to 

您是否正在使用 java.sql.Timestamp 在这里?如果是的话,你不应该这样做。

Are you using java.sql.Timestamp here? If yes, you shouldn't.

这篇关于HQL(休眠)时间戳范围匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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