• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

How to implement three OR criterion using Hibernate?

There has to be a simple explaination for this, but I am trying to create a query using the createCriteria method that has three "OR" conditions.

e.g. Select * from table where field=x or field=y or field=z

I can do it for two driteria, but what about three??  (See code below - sepcifically the line where there is a "<------"
// create the or expressions for open transaction statuses
	        Criterion active = Restrictions.eq("xactionStatusLookup.xactionStatusId",1);
	        Criterion option = Restrictions.eq("xactionStatusLookup.xactionStatusId",2);
	        Criterion pending = Restrictions.eq("xactionStatusLookup.xactionStatusId",3);
	        LogicalExpression orExp = Restrictions.or(active,option,pending);  <---- **** THIS ONLY TAKES 2 PARAMETERS
			List<Xaction> results = (List<Xaction>) sessionFactory
					.setFetchMode("contact", FetchMode.JOIN)
					.addOrder( Order.asc("propStreet") )
					.addOrder( Order.asc("propNum") )

Open in new window

1 Solution
Kevin CrossChief Technology OfficerCommented:
I believe you can put an Or expression as one of the parameters so you chain them; however, I would recommend use of IN like:

field IN (1, 2, 3)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now