aspose file tools
The moose likes Object Relational Mapping and the fly likes hibernate either / or query? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "hibernate either / or query?" Watch "hibernate either / or query?" New topic
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hibernate either / or query?
 
Similar Threads
Hibernate Newbie, help on queries that do some grouping
comparing two table - hibernate criteria
converting from Hibernate to JDBC???
Need help for Many to Many association
Hibernate 3.0 Questions