views:

19

answers:

1

I want to translate the following HQL into Criteria notation:

from Deal
where CURRENT_DATE between startDate and endDate

I tried using Restrictions.between but it doesn't recognize current_date

Criteria c = session().createCriteria(Deal.class)
   .add(Restrictions.between("CURRENT_DATE", "startDate", "endDate");
A: 
  1. Actually this function is called current_date. So you need to use it in lowercase.
  2. Your between criteria is used incorrect, first parameter is name of the property, second and third are values.

To solve the issue you need to rewrite it in the following way:

 Criteria c = session().createCriteria(Deal.class)
    .add(Restrictions.gt("startDate", "current_date")
    .add(Restrictions.lt("endDate", "current_date");
uthark
I get an error: java.lang.String cannot be cast to java.util.Date Isn't there any way to tell hibernate that is not just a string but a function call?
Psyconn
Try to add parenthesis - ()
uthark
It doesn't work with parenthesis either. I'll try a fresh install at the end of the week, maybe it's something in my environment.
Psyconn