HQL query to select data between two dates not returning any record

落爺英雄遲暮 提交于 2021-02-08 11:22:49

问题


ReportView

I'm getting values of Dates from JavaFX DatePicker objects tDateFrom, tDateTo.

I've tried,

(1)

List list = session.createQuery("from ReportView where date between :stDate and :edDate")
                    .setTimestamp("stDate", Date.from(Instant.from(tDateFrom.getValue().atStartOfDay(ZoneId.systemDefault()))))
                    .setTimestamp("edDate", Date.from(Instant.from(tDateTo.getValue().atStartOfDay(ZoneId.systemDefault()))))
                    .list();

(2)

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date frmDate = format.parse(tDateFrom.getValue().toString());
Date enDate = format.parse(tDateTo.getValue().toString()); 

list = session.createQuery("from ReportView where date between :stDate and :edDate")
               .setTimestamp("stDate", frmDate)
               .setTimestamp("edDate", enDate)
               .list();

Both methods are not returning any row.

java.text.ParseException: Unparseable date: "2020-02-03"
    at java.text.DateFormat.parse(DateFormat.java:366)

I've tried to fire query as mentioned in answer of this question : mysql select query where date = ... not returning data

But this query works in mySQL, not in HQL. How to use between clause for dates in HQL?

来源:https://stackoverflow.com/questions/60182463/hql-query-to-select-data-between-two-dates-not-returning-any-record

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!