title: How to schedule a Hibernate program once in a day
body: <p>I am using Spring REST with Hibernate and I have developed a program in which data is coming from database calculate and it is updated into another table in database. But I want to run this program once in a day at a given time because I want to calculate result only one time in a day. How can I do this?</p>
  
  <p>Here is my <strong>DAO</strong> class</p>
  
  <pre><code>@SuppressWarnings({ "unchecked", "rawtypes" })
    public List&lt;Result&gt; getPostList() throws Exception {
        session = sessionFactory.openSession();
        tx = session.beginTransaction();
  
        Criteria cr = session.createCriteria(Post.class);
        ProjectionList projList = Projections.projectionList();
        projList.add(Projections.sum("val"), "topValue");
        projList.add(Projections.groupProperty("userId"), "uid");
        cr.addOrder(Order.desc("topValue"));
        cr.setProjection(projList);
        cr.setResultTransformer(Transformers.aliasToBean(Result.class));
        List&lt;Result&gt; postList = cr.list();
        // please make sure that you are using the class field name rather than database field name in below query.
        String updateHql = "update Result set topValue = :topValue where id = :uid";
        Query query = null;
        int count = 1;
        for(Result result : postList){
          query=session.createQuery(updateHql);
         // query.setLong("topValue", result.getTopValue());
          query.setLong("topValue", count);
          query.setLong("uid", result.getUid());
          count++;
          query.executeUpdate();
          session.flush();
        }
  
        session.flush();
        tx.commit();
        return postList;
    }
  </code></pre>
  
  <p>Here is my <strong>Controller</strong></p>
  
  <pre><code>@RequestMapping(value = "/posts", method = RequestMethod.GET)
  public @ResponseBody
  List&lt;Result&gt; getEmployee() {
  
      List&lt;Result&gt; postList = null;
      try {
          postList = profileService.getPostList();
  
      } catch (Exception e) {
          e.printStackTrace();
      }
  
      return postList;
  }
  </code></pre>