`
dragon0929
  • 浏览: 76312 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

HQL 中日期类型比较

 
阅读更多

查询当天的数据

 

public List<OJBMatch> getTopMatchesForCandidate(final CandidateProfileType profile, final int top, final boolean order) {

  HibernateCallback callback = new HibernateCallback() {
   public Object doInHibernate(Session session)
     throws HibernateException, SQLException {
    String query = "from OJBMatch " +
    "where candidateProfile = ? " +
    " and displayDate >= ?  and displayDate < ? " +
    "order by matchDate desc";
    if (order) {
     query += ", score desc";
    }
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    Date begin = cal.getTime();
    cal.add(Calendar.DATE, 1);
    Date end = cal.getTime();
    
    List<Object> list = session
      .createQuery(query)
      .setFetchSize(top)
      .setMaxResults(top)
      .setInteger(0, profile.getDbId())
      .setDate(1, begin)
      .setDate(2, end)
      .list();

    return list;
   }
  };
  return (List<OJBMatch>) hibernateTemplate.execute(callback);
 }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics