Forums de discussion

DynamicQuery Like with OR Operator

thumbnail
Jawad Saleem, modifié il y a 9 années.

DynamicQuery Like with OR Operator

New Member Publications: 10 Date d'inscription: 07/01/15 Publications récentes
I want to add search filters LIKE attribute with OR Operator, Below code automatically add AND criteria with LIKE.

Junction disjunction = RestrictionsFactoryUtil.disjunction();

if(Validator.equals(propertyName, "firstName")) {
Property firstName = PropertyFactoryUtil.forName("firstName");
disjunction .add(firstName.like(keywords));
}

if(Validator.equals(propertyName, "lastName")) {
Property lastName = PropertyFactoryUtil.forName("lastName");
disjunction .add(lastName.like(keywords));
}

if(Validator.equals(propertyName, "email")) {
Property email = PropertyFactoryUtil.forName("email");
disjunction .add(email.like(keywords));
}

customerDynamicQuery.add(disjunction);
thumbnail
mohammad azaruddin, modifié il y a 9 années.

RE: DynamicQuery Like with OR Operator

Expert Publications: 492 Date d'inscription: 17/09/12 Publications récentes
try this

Criterion criterion1 = RestrictionsFactoryUtil.like("firstName", keywords);
Criterion criterion2 = RestrictionsFactoryUtil.like("lastName", keywords);
Criterion criterion3 = RestrictionsFactoryUtil.like("email", keywords);
Criterion criterion4 = RestrictionsFactoryUtil.or(criterion1, criterion2);
Criterion criterion5 = RestrictionsFactoryUtil.or(criterion4, criterion3);
customerDynamicQuery.add(criterion5);