I want to write a hibernate criteria that excludes certain entities. Here's what I have so far:
Criterion exclusion1 = Restrictions.not(Restrictions.conjunction()
.add(Restrictions.eq("color", "blue");
.add(Restrictions.eq("type", "aaa"))
.add(Restrictions.eq("subtype1", "bbb"))
.add(Restrictions.eq("subtype2", "ccc"));
Criteria crit = session.createCriteria(MyObject.class);
crit.add(exclusion1);
List result = crit.list();
There are several such exclusion criterion. This seems to do what I want except that if any of the fields are null I want it to be included. e.g an entity with color = blue, type = aaa, subtype1 and subtype2 are null to be included.
How can I rewrite this to not exclude that entity?