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

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

    You want to use Restrictions.disjuntion(). Like so

    session.createCriteria(Whatever.class)
        .add(Restrictions.disjunction()
            .add(Restrictions.eq("name", queryString))
            .add(Restrictions.eq("address", queryString))
            .add(Restrictions.eq("phoneNumber", queryString))
        );
    

    See the Hibernate doc here.

提交回复
热议问题