开发者

how to combine java.util.Calendar and HQL Between

开发者 https://www.devze.com 2022-12-11 07:51 出处:网络
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.

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开发者_Go百科 object. and loaned is Javva.Util.Calendar.


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号