Given the following:
Predicate isOwnedByUser = cb.equal(root.get("owner").get("id"), userId); Predicate ownerIsNull = cb.isNull(root.get("owner")); Predicate ownerMatchesOrIsNull = cb.or(ownerIsNull, isOwnedByUser);
The isNull predicate will only match records when NOT inside the OR predicate. The other predicate works normally within or outside the OR.