I try get a list by criteria using Restrictions.ne("status","ERROR") but method returns the list without entities where status is null.
public List<Match_soccer> getDayMatches(Date day){
//Match_soccer where date between start and end dates and status != null
Criteria criteria = session.createCriteria(Match_soccer.class);
criteria.add(Restrictions.between("start", day, DateJobs.addnHours(DateJobs.nextDay(day), 3)));
criteria.add(Restrictions.ne("status","ERROR"));
return criteria.list();
}
Include an explicit null check:
criteria.add(Restrictions.or(
Restrictions.ne("status","ERROR"),
Restrictions.isNull("status"))
);
The point is that most databases evaluate comparison operators with null arguments to false, meaning that both status = null and status <> null are considered false.
The criteria is well written, it should work .
Have you tried to remove the date filter to see if that is filtering "status=null" ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With