简体   繁体   English

两列的休眠条件计算

[英]Hibernate criteria calculation of two columns

I have a class called task which is as: 我有一个叫做task的类,它是:

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. 阈值是DueDate用户希望以小时为单位的通知之前的小时数。 I created a quartz job which starts every hour and should get all task which are as follows 我创建了一个石英工作,每小时开始一次,应该可以完成以下所有任务

now > dueDate-treshold 现在> DueDate-treshold

How can I do that? 我怎样才能做到这一点?

Calculate calculatedThreshold = now - dueDate . 计算calculatedThreshold = now - dueDate

Then use one of 2: 然后使用以下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(); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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