-->
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.  [ 3 posts ] 
Author Message
 Post subject: Criteria and Collections with parent-child relationship
PostPosted: Tue Apr 20, 2004 8:38 am 
Beginner
Beginner

Joined: Fri Oct 17, 2003 4:11 am
Posts: 40
Hallo!
I have a Parent class with some Children in a Set. I ask the user to give me some children's id and I use them to get the Parent that contains at least this children.
If the user give me only one child (with id=1 for example) it's simple:
Code:
Criteria criteria = session.createCriteria(Parent.class);
Criteria childrenCriteria = criteria.createCriteria("subChildren");
childrenCriteria.add( Expression.eq("id", new Integer(1)) );
List results = criteria.list();


If the user tell me "give me the Parent that have at least the children with id=1 and id=2" i tried with the conjunction of two Expression.eq but it doesn't work!! I get no result!

There is a way to make this with Criteria (no Query)?

Thanx for any help and sorry for my english!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 20, 2004 8:41 am 
Beginner
Beginner

Joined: Fri Oct 17, 2003 4:11 am
Posts: 40
My whole code is:

Code:
Criteria criteria=session.createCriteria(HUtente.class);
HUtente hu=new HUtente();
hu.username="i%";
Example example=Example.create(hu);
example.ignoreCase();
example.enableLike();
example.excludeZeroes();
criteria.add(example);

Criteria childCriteria=criteria.createCriteria("gruppi");
childCriteria.add(Expression.disjunction().add(Expression.eq("id",new Long(1))).add(Expression.eq("id",new Long(2))));
List list=criteria.list();


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 20, 2004 9:03 am 
Beginner
Beginner

Joined: Fri Oct 17, 2003 4:11 am
Posts: 40
with disjunction it works! But is the OR case... i need AND case...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.