I have a Criteria checking that the value of a date column is less than a given date.
Here is the Dao method:
Code:
public List<User> findNotValid(DateTime dateTime) {
Criteria criteria = getSession().createCriteria(User.class);
criteria
.add(Restrictions.lt("validUntil", dateTime))
.addOrder(Order.asc("firstname")).addOrder(Order.asc("lastname"));
return criteria.list();
}
The problem is that, if the date column contains not date, but simply the value 0000-00-00 00:00:00 then the criteria "less than" returns a match.
So I need to have also another criteria to ensure the date is actually set, and is not a 0000-00-00 00:00:00
The isNotNull cannot solve this issue as the value 0000-00-00 00:00:00 is not a null value. So I cannot use the following criteria:
Code:
.add(Restrictions.isNotNull("validUntil"))
I also cannot use the following criteria:
Code:
.add(Restrictions.ne("validUntil", "0000-00-00 00:00:00"))
as it triggers an exception for attempting to cast a String to a DateTime
Code:
testException = java.lang.ClassCastException: java.lang.String cannot be cast to org.joda.time.DateTime
Is there any way to have a criteria that checks for not 0000-00-00 00:00:00 ?