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.