blaze-persistence

Blaze Persistence skip null parameters in where expression


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


Solution

  • 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);
    }