-->
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.  [ 5 posts ] 
Author Message
 Post subject: design question regarding criteria and disjunctions
PostPosted: Wed Jan 28, 2009 5:33 pm 
Newbie

Joined: Thu May 01, 2008 11:52 am
Posts: 17
I am not sure how to make a disjunction on a criteria's associations.

I know how to filter people based on their associations (e.g. "clubs" or "hobbies")

Code:
//this is, effectively, an "and" search
//search for people...
Criteria pCrit = sess.createCriteria(Person.class);
//further filter on both club or hobbies
pCrit.createCriteria("clubs");
pCrit.createCriteria("hobbies");

But what if I wanted to search on either club or hobbies?

Code:
//I can create a disjunction, and add it to the root people criteria..
Junction dJunc = Expression.disjunction();
pCrit.add( dJunc );

//but how do I add the Person class's associated critera  to a disjunction?


Thanks for any help. I think I am missing something here.


Top
 Profile  
 
 Post subject: Re: design question regarding criteria and disjunctions
PostPosted: Wed Jan 28, 2009 7:46 pm 
Newbie

Joined: Thu May 01, 2008 11:52 am
Posts: 17
Stated more simply, how do I make this sort of query:

Code:
Criteria pCrit = sess.createCriteria(Person.class);


Criteria clubCrit = pCrit.createCriteria("clubs"); // add complicated stuff to this criteria object

// OR

Criteria hobbyCrit = pCrit.createCriteria("hobby"); // add compicated stuff to this criteria object


pCrit.list(); //people in certain clubs or with certain hobbies


Top
 Profile  
 
 Post subject: Re: design question regarding criteria and disjunctions
PostPosted: Mon Jul 20, 2009 3:08 pm 
Newbie

Joined: Mon Jul 20, 2009 3:03 pm
Posts: 2
I have the same problem and I can not find how to do this ... !!


Top
 Profile  
 
 Post subject: Re: design question regarding criteria and disjunctions
PostPosted: Mon Jul 20, 2009 4:28 pm 
Newbie

Joined: Thu May 01, 2008 11:52 am
Posts: 17
In the end, I was only able to accomplish this using HQL. It was a good transition.


Top
 Profile  
 
 Post subject: Re: design question regarding criteria and disjunctions
PostPosted: Mon Jul 20, 2009 5:00 pm 
Newbie

Joined: Mon Jul 20, 2009 3:03 pm
Posts: 2
In what countered it's the only possible solution, but it is bizarre, that the API Criteria doesn't propose a feature or a concept for the same case.


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