I am working on a Spring-MVC application in which I am using scheduling to delete extra stuff which is not necessary. Unfortunately, my scheduled method did not fire. Can anyone tell me what I did wrong.
Here is the code :
@Repository
@Transactional
@EnableScheduling
public class NotificationDAOImpl implements NotificationDAO{
@Override
@Scheduled(cron = "0 3 3 * * ?")
public void deleteNotificationsAutoMagically(){
session=this.sessionFactory.getCurrentSession();
long now = System.currentTimeMillis();
long nowMinus1Week = now - (1000 * 60 * 60 * 24 * 3);
Timestamp nowMinus1WeekAsTimeStamp = new Timestamp(nowMinus1Week);
Query query = session.createQuery("delete from NoteLock as nl where nl.timestamp < :limit and nl.read=:true");
query.setParameter("limit", nowMinus1WeekAsTimeStamp);
query.executeUpdate();
session.flush();
}
}
I know parameter name is for 1 week, but I am deleting it in 3 days. I just copied the code .. :D Any help would be nice. Thanks.