spring - Hibernate : HQL query to directly compare timestamp from database value -


  • i working on spring-mvc application using hibernate orm , postgresql database, in saving in database row values(obvious). information, saving timestamp(java.sql.timestamp) when entry made. reasons want remove entries older 5 minutes.

how possible me give hql query timestamp, if timestamp>oldtimestamp delete row. have till :

 @override     @scheduled(fixedrate = 100000)     public void removestalelocks() {         session = this.sessionfactory.getcurrentsession();     //timestamp timestamp = // current timestamp;         query query = session.createquery("delete notelock nl nl.timestamp=:timestamp");         query.setparameter("timestamp",timestamp);         query.executeupdate();         session.flush();     } 

what pass query parameter use current timestamp denoting currenttime, , delete notes more 5 minutes old. nice. lot.

long = system.currenttimemillis(); long nowminus5minutes = - (5l * 60l * 1000l); timestamp nowminus5minutesastimestamp = new timestamp(nowminus5minutes);  query query = session.createquery("delete notelock nl nl.timestamp < :limit"); query.setparameter("limit", nowminus5minutesastimestamp); query.executeupdate(); 

Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -