Link to home
Start Free TrialLog in
Avatar of burtonrhodes
burtonrhodes

asked on

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
				.getCurrentSession()
				.createCriteria("com.rre.model.Xaction")
					.add(orExp)
					.add(Expression.eq("xactionStatusLookup.xactionStatusId",2))
					.setFetchMode("contact", FetchMode.JOIN)
					.addOrder( Order.asc("propStreet") )
					.addOrder( Order.asc("propNum") )
					.list();

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial