| Author |
hibernate either / or query?
|
Erik Blank
Greenhorn
Joined: Jan 28, 2009
Posts: 2
|
|
Using hibernate, how do I make an "OR" query between two criteria?
For example, we start with this root Criteria:
Then we instantiate two associated criteria...
Now how do I specify that my pCrit query should return matches from either/or of these two criteria?
It is important that I can keep / access the criteria objects (e.g. clubCrit, hobbyCrit).
Thanks!
|
 |
wangch ch
Greenhorn
Joined: Jul 11, 2012
Posts: 1
|
|
You can either "or" one more restriction to the result:
Criteria criteria = session.createCriteria(Reader.class);
criteria.add(Restrictions.or(Restrictions.or(condition1, condition2), condition3));
or use Disjunction:
Criteria criteria = session.createCriteria(Reader.class);
Junction conditionGroup = Restrictions.disjunction();
conditionGroup.add(condition1).add(condition2).add(condition3);
criteria.add(conditionGroup);
from http://stackoverflow.com/questions/5859058/how-to-make-a-criteria-query-with-3-or-criterions-properly
|
 |
Alex Armenteros
Ranch Hand
Joined: May 05, 2010
Posts: 60
|
|
|
If you post an aproximate representation of your model, we could help you better.
|
 |
 |
|
|
subject: hibernate either / or query?
|
|
|