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 "<------"
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();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.