Hibernate Query to fetch records on date ignoring timestamp

岁酱吖の 提交于 2019-12-06 07:04:08
String hql = "from POJO as POJO where to_date(to_char(POJO.tradeDate, 'DD-MON-YY'), 'DD-MON-YY') = :date"; 
Query query = getSession().createQuery(hql); 
query.setParameter("date", date); 

[Edit]

Beware, the index, if there is any, on tradeDate will not be used if you follow the above query. In case, there are some performance concerns, you can rather do it like this,

String hql = "from POJO as POJO where POJO.tradeDate between :date and :ceilDate"; 
Query query = getSession().createQuery(hql); 
// a date having timestamp part, 00:00:00.0, or missing completely
query.setParameter("date", date); 
// a date having timestamp part, 23:59:59.999
query.setParameter("ceilDate", ceilDate); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!