Issue
I'm trying to do a basic "OR" on three fields using a hibernate criteria query.
Example
class Whatever{
string name;
string address;
string phoneNumber;
}
I'd like to build a criteria query where my search string could match "name" or "address" or "phoneNumber".
Solution
You want to use Restrictions.disjuntion()
. Like so
session.createCriteria(Whatever.class)
.add(Restrictions.disjunction()
.add(Restrictions.eq("name", queryString))
.add(Restrictions.eq("address", queryString))
.add(Restrictions.eq("phoneNumber", queryString))
);
See the Hibernate doc here.
Answered By - sblundy