title: How to get most recent record based on last_modified field in hibernate JPA(session implementation)
body: <p>I've been scratching my head over the past 3 hours to find the most recent object using hibernate.i've made attempts but always returns either null, or castTypeExcetpion.</p>
  
  <pre><code>public Content getMostRecentByCategoryAndGenre(Category category, Genre genre){
      logger.info("calling getMostRecentByCategoryAndGenre");
      logger.debug(category);
      logger.debug(genre);
  
      DetachedCriteria recentDate = DetachedCriteria.forClass(this.getPersistentClass());
      recentDate.setProjection(Projections.max("lastModified"));
  
      Content recent = (Content)  this.getSessionFactory().getCurrentSession().createCriteria(this.getPersistentClass())
              .add(Restrictions.eq("genre", genre))
              .add(Restrictions.eq("category", category))
              .setProjection(Projections.max("lastModified")) // gives cannot cast timestamp to com.bla.bla.bla.myproject
  
           // .add(Property.forName("lastModified").eq(recentDate)) // this if uncommented and previous line commented gives null result 
              .uniqueResult();
      logger.debug(recent);
      return recent;
  }
  </code></pre>
  
  <p>is there anything i'm not doing right? thanks for reading this.</p>