Skip to content

Creating restriction groups

gert-wijns edited this page Sep 13, 2014 · 2 revisions

When working with 'or' restrictions, you need to be able to include brackets to group restrictions. This can be achieved by creating restriction groups.

Restriction groups can also be used to create a list of 'and' restrictions.

RestrictionsGroupFactory rb = query.getGroupedRestrictionsBuilder();
House house = query.from(House.class);

query.and(
    rb.or(
        rb.where(house.getStyle()).eq(Style.the1980s),
        rb.where(house.getFloors()).gt(2)),
    rb.where(house.getName()).startsWith("Castle"));

=> "from House hobj1 
    where (hobj1.style = :np1 or hobj1.floors > :np2) 
      and hobj1.name like :np3"
params [np1=Style.the1980s, np2=2, np3="Castle%"]
Clone this wiki locally