如何在hibernate中为以下查询创建条件:
select * from xmppserveripinfo where update_dt > (select DATE_SUB(NOW(),INTERVAL 1 MINUTE))
答案 0 :(得分:1)
此示例演示了它的工作原理:
public List<XmppServerIpInfo > find(final int intervalInMinutes) {
return getHibernateTemplate().execute(new HibernateCallback<List<XmppServerIpInfo>>() {
public List<XmppServerIpInfo> doInHibernate(Session session) throws HibernateException, SQLException {
Criteria crit = session.createCriteria(XmppServerIpInfo.class);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MINUTE, -intervalInMinutes);
crit.add(Restrictions.ge("updateTime", cal.getTime()));
crit.addOrder(Order.asc("updateTime"));
return crit.list();
}
});
}