title: How to query a date in HQL (Hibernate) with Joda Time?
body: <p>I am sure that someone familiar with HQL (I am myself a newbie) can easily answer this question.</p>
  
  <p>In my Grails application, I have the following domain class.</p>
  
  <pre><code>class Book {
    org.joda.time.DateTime releaseDate //I use the PersistentDateTime for persisting via Hibernate (that use a DATETIME type for MySQL DB)
  }
  </code></pre>
  
  <p>In my HQL query, I want to retrieve books whose release date is included in range <code>date1</code>..<code>date2</code></p>
  
  <p>For instance I tried:</p>
  
  <pre><code>DateTime date1, date2
  ... 
  def queryStr = "select * from Book as b where b.releaseDate &gt; $date1 and b.releaseDate &lt; $date2" 
  def res = Book.executeQuery(queryStr)
  </code></pre>
  
  <p>But I got the exception <code>...caused by: org.springframework.orm.hibernate3.HibernateQueryException: unexpected token:</code>
  The error token points to date format (for instance <code>2009-11-27T21:57:18.010+01:00</code> or <code>Fri Nov 27 22:01:20 CET 2009</code>)</p>
  
  <p>I have also tried to convert date1 into a Date class without success </p>
  
  <p>So what is the correct HQL code ? Should I convert to a specific format (which one?) using the patternForStyle method or is there another -cleaner- way to do it?</p>
  
  <p>Thanks,</p>
  
  <p>Fabien.</p>