如何将 java.util.Calendar 和 HQL 结合起来

发布于 2024-08-11 06:17:51 字数 346 浏览 8 评论 0原文

我正在尝试获取在两个日期之间借出的书籍。 由于数据有可爱的 2009 年显示为 109 个功能,我决定使用日历。

然而,在编写 HQL 时,我遇到了 BETWEEN 不将日历视为日期的问题。 现在我想知道是否有解决方案。 或者我是否一直在类中编写函数来获取小时、日、月、年并编写一个很长的 where 语句?

query = session.createQuery("from model.Book book where book.loaned Between :earliest and :latest");

问题是 Between 只适用于日期对象。借用的是Javva.Util.Calendar。

I'm trying to get the books that were loaned between two dates.
Since data has the lovely 2009 is shown as 109 feature I decided to use calendars.

However when writing my HQL I ran into the problem that BETWEEN doesn't view a Calendar as a date.
Now I'm wondering if there's a solution for this.
Or am I stuck writing functions in my class to get the hour, day, month, year and write a long where statement?

query = session.createQuery("from model.Book book where book.loaned between :earliest and :latest");

The problem is that the between only works with a date object. and loaned is Javva.Util.Calendar.

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

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

发布评论

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

评论(1

恍梦境° 2024-08-18 06:17:51

您可以使用 Calendar.getTimeCalendar 获取Date - 这对您有帮助吗?诚然,如果您不小心,您可能会遇到时区问题...数据库中存储的日期到底是如何的?

You can get a Date from a Calendar using Calendar.getTime - does that help you? You may run into time zone issues if you're not careful, admittedly... how exactly are the dates stored in the database?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文