Hibernate - filter Single Column data using date where clause

Viewed 900

Lets say One table ABC having two column i.e. ID & CREATED_DATE

I want to fetch those ID which is created lets say '09-11-2017' and '09-17-2017'

Below SQL query working fine but I want to implement same logic using hibernate.

select ID from ABC where between TO_DATE('09-11-2017', 'MM-DD-YYYY')  AND TO_DATE('09-17-2017', 'MM-DD-YYYY')

My code is not working.

public List getData(final Date startDate, final Date endDate){

    String sqlString = "select ID from ABC where CREATED_DATE between :startDate and :endDate";
    SQLQuery query = getSession().createSQLQuery(sqlString);
    query.setParameter(CREATED_DATE);
    return query.list();
}
3 Answers
Related