开发者

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

开发者 https://www.devze.com 2023-03-02 12:08 出处:网络
I\'d like to make a criteria query with 3 OR Criterions and I dont know what is the best way to do it.

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(Restric开发者_运维问答tions.or(Restrictions.like(PUBLICATION_ID_FIELD, "Question",MatchMode.END), Restrictions.like(PUBLICATION_ID_FIELD, "Idea",MatchMode.END)));

How can I add a third one ?


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);


You may refer to this link for more detailed explanation for conjunction and disjunction

How to use Hibernate Criteria objects for multiple and/or conditions

0

精彩评论

暂无评论...
验证码 换一张
取 消