0

is there a way to skip null parameters in where expression? Let's suppose I have the following code:

Boolean deleted = null;
var criteriaBuilder = cbf.create(em, MyClass.class)
                 .where("deleted").eq(deleted);

I would want to skip the evaluation of "deleted" when the deleted variable is null. Is there a way to accomplish this?

Thanks euks

E. Marotti
  • 89
  • 7

1 Answers1

1

This is usually done by conditionally adding the predicate like this:

var criteriaBuilder = cbf.create(em, MyClass.class);
if (deleted != null) {
    criteriaBuilder.where("deleted").eq(deleted);
}
Christian Beikov
  • 15,141
  • 2
  • 32
  • 58
  • Thanks. I've used this strategy. – E. Marotti Apr 30 '21 at 13:44
  • Hello @Christian Beikov. Can you please check this question? https://stackoverflow.com/questions/69253704/is-blaze-persistence-querydsl-integration-support-projections How I can get the total count for this query even I used pagination? – java dev Sep 20 '21 at 14:12