-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Criteria API, negated criterion on nested Collections
PostPosted: Wed Oct 13, 2010 7:04 am 
Newbie

Joined: Wed Oct 13, 2010 5:47 am
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: Criteria API, negated criterion on nested Collections
PostPosted: Mon Oct 25, 2010 9:12 am 
Newbie

Joined: Wed Oct 13, 2010 5:47 am
Posts: 2
can somebody help???

or is this criterion unrealizable ?


thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.