1

I am working on a Spring-MVC project with Hibernate and DB as Postgres in which there is a possibility to assign tasks to individual people who are part of a group.

Now the tasks have end-time, and I have a scheduler running which every 30 minutes would check if task has around 48hours remaining to finish, if that's the case, then I would send an email.

Unfortunately, I cannot just check for less than 48 hours, as I am also checking for less then 12 hours and less then 8hours.

So, I thought why not to check that the time remaining is between 47-48hours. And I don't know how to check such a condition.

So, basically, from the current time, if the row has a timestamp which is 47-48hours far away, I want to retrieve that row. I know how to check for more then what is now, and below is the code. Can anyone help me how to check within 47-48hours. Thanks a lot.

Code :

   @Override
       public List<GroupNotes> findGroupNotesWithExpiryInFortyEightHours() {
            int val = 0;
            Session session = this.sessionFactory.getCurrentSession();
            Timestamp timestamp = new Timestamp(System.currentTimeMillis());
            Query query = session.createQuery("from GroupNotes as gn where gn.zugwisenPersonId!=:val and gn.timeToend>:timestamp");

        }

Thanks a lot.

We are Borg
  • 5,117
  • 17
  • 102
  • 225
  • Which database are you using and can you allowed to do it in CreateSqlCreteria I mean with sql not with HQL – erhun Sep 16 '15 at 14:43
  • @erhun : I can use SQL queries as well, I am using Postgres. – We are Borg Sep 16 '15 at 14:44
  • 1
    You can check interval usage in Postgresql in that SO questions there is some http://stackoverflow.com/questions/9376350/postgresql-how-to-concat-interval-value-2-days – erhun Sep 16 '15 at 14:47

1 Answers1

3

This query should do the job (it was not tested it though, I do not have an IDE here):

long currentTime = System.currentTimeMillis();
long plus47Hours = currentTime + (47 * 60 * 60 * 1000);
Timestamp plus47HoursTS = new Timestamp(plus47Hours);

long plus48Hours = currentTime + (48 * 60 * 60 * 1000);
Timestamp plus48HoursTS = new Timestamp(plus48Hours);

Query query = session.createQuery("from GroupNotes as gn where gn.zugwisenPersonId!=:val and gn.timeToend > :from and gn.timeToend < :to");
query.setParameter("from", plus47HoursTS);
query.setParameter("to", plus48HoursTS);
Gergely Bacso
  • 14,243
  • 2
  • 44
  • 64