I have some problems with negated criterions.
Structur:Class A have a member “bColl” (Collection<Class B>)
Class B have a member “cColl” (Collection<Class C>)
Class C have a member “value” (String)
Instances in DB:a0 (bColl is empty)
a1 (bColl contains one element, cColl is empty)
a2 (bColl contains one element, cColl contains one element, contains value “aaa”)
a3 (bColl contains one element, cColl contains one element, contains value “bbb”)
I need all instances of Class A, who contains not value “aaa” in the collection cColl.
The result should be: a0, a1, a3
but the result contains only a3
--> value “aaa” not in cColl
OR cColl is empty
OR bColl is empty
Code:
Criteria criteria = session.createCriteria(A.class);
criteria.createAlias("bColl", "b");
criteria.createAlias("b.cColl", "code");
Criterion c1 = Restrictions.isEmpty("bColl");
Criterion c2 = Restrictions.isEmpty("b.cColl");
Criterion c3 = Restrictions.not(Restrictions.like("code.value", "aaa", MatchMode.ANYWHERE));
Junction or = Restrictions.disjunction().add(c1).add(c2).add(c3);
criteria.add(or);
List<A> result = criteria.list();
This criteria work, but returns the wrong result.
I get only
a3, because the a3 contains a value and the value is not “aaa”, but
a0 and
a1 also contains not the value “aaa”
I get the same result by using
--> value “aaa” not in cColl
What is wrong ?
Can somebody help ?
Thanks a lot