I had the same problem. I'm using Criteria and have something like this:
Code:
Criteria criteria = session.createCriteria(Cat.class);
criteria.add( Restrictions.or(
Restrictions.like("name", "%"+searchParam+"%").ignoreCase(),
Restrictions.like("color", "%"+searchParam+"%").ignoreCase()
));
This works but you can only add two Criterions. To compare more fields you can use Disjunction:
Code:
criteria.add( Restrictions.disjunction()
.add(Restrictions.like("name", "%"+searchParam+"%").ignoreCase())
.add(Restrictions.like("color", "%"+searchParam+"%").ignoreCase())
.add(Restrictions.like("lastName", "%"+searchParam+"%").ignoreCase())
);
What I still don't get is how to add associated restrictions to a disjuction.
Code:
criteria.createCriteria("kittens").add( Restrictions.like("color", "%"+searchParam+"%").ignoreCase() );
How would you throw this in the mix?