Search code examples
javaspringdatehqlwhere-clause

How to compare two date in a maven application java


I create a function to fetch some rows that matches the Date. But the function is not performing accordingly. I suspect there is some syntax issue. Please help me finding the issue. The DaoImpl funtion is given below:

public List<ReportSewing> getReport(Date reportDate) {
     return session.getCurrentSession()
             .createQuery("from ReportSewing where DATE(reportDate) = (reportDate)")
             .list();
}

Solution

  • Seems like you forgot to pass query parameter.

    public List<ReportSewing> getReport(Date reportDate) {
         return session.getCurrentSession()
             .createQuery("from ReportSewing where DATE(reportDate) = :reportDate")
             .setParameter("reportDate", reportDate)
             .list();
    }