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

前端 未结 8 916
终归单人心
终归单人心 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:13

        //Expression :  (c1 AND c2) OR (c3)      
    
    
         Criteria criteria = session.createCriteria(Employee.class);
    
          Criterion c1 = Restrictions.like("name", "%e%");
          Criterion c2 = Restrictions.ge("salary", 10000.00);
          Criterion c3 = Restrictions.like("name", "%YYY%");
          Criterion c4 = Restrictions.or(Restrictions.and(c1, c2), c3);
          criteria.add(c4);
    

    //Same thing can be done for (c1 OR c2) AND c3, or any complex expression.

提交回复
热议问题