简体   繁体   中英

Hibernate criteria calculation of two columns

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?

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(); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM