To dynamically add restrictions to a query I used the following way: CriteriaBuilder cb = session.getCriteriaBuilder(); Predicate restriction = cb.and(); List<Expression<Boolean>> restrictions = restriction.getExpressions(); if (…) { restrictions.add(cb.equal(root.get(Table_.column), …); } cq.select(root) .where(restriction) After migration my application to Spring Boot 3 with Hibernate 6 this does not work anymore: Predicate is of type SqmComparisonPredicate wich extends AbstractNegatableSqmPredicate which extends AbstractSqmPredicate: @Override public List<Expression<Boolean>> getExpressions() { /// most predicates do not have sub-predicates return new ArrayList<>(0); } Every time getExpressions() is called a new array is created which is not stored in the Predicate, therefore “restriction” is “empty” i.e. does not contain any restriction added before. |