orm - How to query a date in HQL (Hibernate) with Joda Time? -
I'm sure anyone is familiar with HQL (I'm a newbie myself) can easily answer this question .
In my Grails application, I have the following domain class.
class book {org.joda.time.DateTime releaseDate // I use PersistentDateTime to continue through hibernate (which is a DATETIME type in my HQL query, I I want to retrieve the books which are included in the date range of the release date1
.. date2 Date Book date 1, Date 2 ... def queryStr = "Book with 'b * where b.releaseDate & gt; $ date1 and B.releaseDate & lt; $ date2" def res = Book.executeQuery (queryS Tr)
but I have exceptions ... due to: org.springframework.orm.hibernate3.HibernateQueryException: unexpected token:
error token digits in date format ( For example 2009-11-27T21: 57: 18.010 + 01: 00
or no thank you V 27 22:01:20 CET 2009
)
I also tried to convert date 1 to a date range without success
So what is the correct HQL code? Do I use a pattern format method to specify a specific format (which is one?). In Should I change or is there another scalar method to do this?
Thanks,
Fabian.
I'm not a Grails expert, but in Java, you usually have date1
and Bind to the date2
query parameter and like this:
string HKL = "Select * b * where b.releaseDate & gt;: date1 and B.release date & lt ;: DATE2 "; Session.createQuery (hql) .setDate ("date1", date1) .setDate ("date2", date2) .list ();
I'm sure you can do something in grails. If not, then do not format your dates as yyyyMMdhhmms
(no spaces) and attach them to single quotes - thus hibernating considers them as stability and MySQL dates them But will convert on.
Comments
Post a Comment