I am building an app using hibernate(spring-jpa more specifically). My model class contain a java.util.Date field and I want to filter the records based on the date field ignoring the time part.
I try to achieve this with spring-jpa specification but for equal operation it always returns 0 objects
I further debug this problem and found that when hibernate return the Object with field type is java.sql.timeStamp where I compare it with java.util.Date so it never matched.
Below is sample code I used for debugging
List<EmployeeLeaves> l = empLeaveDao.findAll();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-DD");
Date date = formatter.parse("2018-04-28");
long time = date.getTime();
date = new java.sql.Timestamp(time);
for (EmployeeLeaves d : l) {
System.out.println(d.getAppliedOn().getClass().getName());
if (d.getAppliedOn().equals(date)) {
System.out.println("==============" + d.getRecordId());
}
}
return l;
Still no luck as two date Objects never match as equals method never returns true.
Can anyone suggest how to create a new Date object so It can equal with Date objects returned by database.