Hello. I have the following problem: when I run the query manually through the command line client:
Code:
select * from book where printed between '2007-10-26 20:12:00' and '2007-10-26 22:12:00'
it works fine, returs one record (as it should).
However, when I use the code:
Code:
Query q = session.createQuery("from Book b where b.printed between :start and :end");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
q.setDate("start", df.parse("2007-10-26 20:12:00"));
q.setDate("end", df.parse("2007-10-26 22:12:00"));
Book book = (Book) q.uniqueResult();
it doesn't.
When I set log level to debug, I can see that Hibernate translates the date parameters according to my locale or something (it outputs:
binding '26 październik 2007' to parameter: 1
binding '26 październik 2007' to parameter: 2
(polish computer)
First, this is different from simple Date.toString() (anyway, toString wouldn't work either), and why doesn't it output the time part?
When I do this:
Code:
q.setString("start", df.parse("2007-10-26 20:12:00"));
q.setString("end", df.parse("2007-10-26 22:12:00"));
the result is again one row. This means the string parameters worked.
But I would like to use java.util.Date / setDate() method. So please could anyone tell me what is the right way to deal with that?
And the another thing is - mysql has only one format for the datetime type (I suppose?). I'm not sure, but what if oracle has many, and it defaults to the server locale, but could be set to something completely customized? Is this true? How can this be dealt with?
Thanks!