How do you “OR” criteria together when using a criteria query with hibernate?

前端 未结 8 927
终归单人心
终归单人心 2020-12-04 07:44

I\'m trying to do a basic \"OR\" on three fields using a hibernate criteria query.

Example

class Whatever{
 string name;
 string address;
 string pho         


        
8条回答
  •  不知归路
    2020-12-04 08:39

    If someone is using CriteriaQuery instead of Criteria, you can put all your expressions in a Predicate list and put a OR by predicates size like this:

    List predicates = new ArrayList<>();
    if (...) {
      predicates.add(...);
    }
    
    criteriaQuery.where(cb.or(predicates.toArray(new Predicate[predicates.size()])));
    

提交回复
热议问题