Hi,
I have a entity with some properties like title and description and a many-to-many association with keywords. I want to do a criteria that returns all rows where 'xyz' is in the title or the description or 'xyz' is a keyword. I can easily do 'and' as below but not 'or'.. Ideas?
Keyword keyword = keywordDAO.findKeywordByName(token,
session);
if (keyword != null) {
Criteria kwCriteria = crit
.createCriteria("keywords");
kwCriteria.add(Restrictions.idEq(keyword
.getKeywordId()));
}
LogicalExpression tokenExpression = Restrictions.or(
Restrictions.like("title", token, MatchMode.ANYWHERE),
Restrictions.like("alternativeTitle", token, MatchMode.ANYWHERE));
tokenExpression = Restrictions.or(tokenExpression,
Restrictions.like("description", token, MatchMode.ANYWHERE));
crit.add(tokenExpression);
Regards,
Damon.
|