Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a criteria query with 3 OR Criterions properly?

I'd like to make a criteria query with 3 OR Criterions and I dont know what is the best way to do it.

Currently I only have 2 or Restrictions.

Criteria crit = session.createCriteria(Reader.class)
.add(Restrictions.or(Restrictions.like(PUBLICATION_ID_FIELD, "Question",MatchMode.END), Restrictions.like(PUBLICATION_ID_FIELD, "Idea",MatchMode.END)));

How can I add a third one ?

like image 866
Kévin_Bransard Avatar asked Dec 04 '22 08:12

Kévin_Bransard


1 Answers

You can either "or" one more restriction to the result:

Criteria criteria = session.createCriteria(Reader.class);
criteria.add(Restrictions.or(Restrictions.or(condition1, condition2), condition3));

or use Disjunction:

Criteria criteria = session.createCriteria(Reader.class);
Junction conditionGroup = Restrictions.disjunction();
conditionGroup.add(condition1).add(condition2).add(condition3);
criteria.add(conditionGroup);
like image 153
ChssPly76 Avatar answered Dec 29 '22 11:12

ChssPly76