0

I have a class called task which is as:

public class task {
    int id;
    Date dueDate;
    int treshold;
}

treshold is how much hour before dueDate user want to get notification in terms of hour. I created a quartz job which starts every hour and should get all task which are as follows

now > dueDate-treshold

How can I do that?

Mikko Maunu
  • 41,366
  • 10
  • 132
  • 135
bdogru
  • 812
  • 1
  • 11
  • 19

1 Answers1

0

Calculate calculatedThreshold = now - dueDate.

Then use one of 2:

  1. Citeria:

    List result = session.createCriteria(task.class).
                          add(Expression.ge("threshold", calculatedThreshold).
                          list();
    
  2. HQL:

    List result = session.createQuery(
                  "from task where threshold >= :calculatedThreshold").
         setParameter("calculatedThreshold", calculatedThreshold).
         list();
    
j3ny4
  • 442
  • 2
  • 8
  • The problem is that, due date is different for every task so direct calculation don't work as expected, i guess calculation should be done within query – bdogru Jun 02 '14 at 06:59
  • Where do you pull those due dates from? Is that another Hibernate mapped entity? If yes, you can do a join query between the 2 entities and make the calculation in the where part of the query. – j3ny4 Jun 02 '14 at 07:50
  • i want to create an sql query as: 'select * from task as t where t.treshold > :now - t.dueDate' – bdogru Jun 02 '14 at 07:59