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

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

    This is what worked for me for an OR condition, that too with an IN condition and not the answer up-voted most on this discussion:

    criteria.add( Restrictions.or(
                        Restrictions.eq(ch.getPath(ch.propertyResolver().getXXXX()), "OR_STRING"),
                            Restrictions.in(ch.getPath(ch.propertyResolver().getYYYY()), new String[]{"AA","BB","CC"})
                        ));
    

    Resulting Query:

      and (
                this_.XXXX=? 
                or this_.YYYY in (
                    ?, ?, ?
                )
            ) 
    

提交回复
热议问题