hibernate HQL 日期差异

发布于 2024-11-27 18:38:13 字数 296 浏览 5 评论 0原文

我想查找映射到具有以下条件的对象 XYZ 的所有记录 A 有日期字段 XyzDateTime (它是时间戳) 现在当前时间-xyzDateTime> 20 我要选择记录

query = session.creatQuery(Select x from XYZ where :currentTime-xyzDateTime > 20 )
query.setParameter("currentTime",new Date())

这是正确的吗?
我可以通过这种方式检查日期差异吗?

I want to find all records which maps to object XYZ with following conditions
A has date field XyzDateTime (its a time stamp)
Now currentTime -xyzDateTime > 20 i want to select the record

query = session.creatQuery(Select x from XYZ where :currentTime-xyzDateTime > 20 )
query.setParameter("currentTime",new Date())

is this correct?
Can i check date difference in this way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热情消退 2024-12-04 18:38:13

这是不正确的。最简单的解决方案就是这样(根本不是最漂亮的解决方案)

Date twentyDaysInFuture = new Date(Calendar.getInstance().add(Calendar.DAY_OF_MONTH, 20).getTime());

query = session.createQuery("SELECT x FROM XYZ x WHERE xyzDateTime > :endDate").setParameter("endDate", twentyDaysInFuture);

It's not correct. Simplest solution is like that (not the prettiest solution at all)

Date twentyDaysInFuture = new Date(Calendar.getInstance().add(Calendar.DAY_OF_MONTH, 20).getTime());

query = session.createQuery("SELECT x FROM XYZ x WHERE xyzDateTime > :endDate").setParameter("endDate", twentyDaysInFuture);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文