Hibernate:HQL 查询直接比较数据库值的时间戳

Hibernate : HQL query to directly compare timestamp from database value

我怎么可能给出带有时间戳的 HQL 查询,比如 if timestamp>oldTimestamp then delete that row。到目前为止,我有这样的事情:

 @Override
    @Scheduled(fixedRate = 100000)
    public void removeStaleLocks() {
        session = this.sessionFactory.getCurrentSession();
    //Timestamp timestamp = // current timestamp;
        Query query = session.createQuery("delete from NoteLock as nl where nl.timeStamp=:timeStamp");
        query.setParameter("timeStamp",timeStamp);
        query.executeUpdate();
        session.flush();
    }

我想做的是向查询传递一个参数,将其用作当前时间戳,表示这是当前时间,并删除所有超过 5 分钟的笔记。你能帮忙的话,我会很高兴。非常感谢。

long now = System.currentTimeMillis();
long nowMinus5Minutes = now - (5L * 60L * 1000L);
Timestamp nowMinus5MinutesAsTimestamp = new Timestamp(nowMinus5Minutes);

Query query = session.createQuery("delete from NoteLock as nl where nl.timeStamp < :limit");
query.setParameter("limit", nowMinus5MinutesAsTimestamp);
query.executeUpdate();