0

I'm using Specification from Spring Data Jpa and trying to compose condition WHERE value is null OR (value >= a AND value <= b) this way:

    return (root, query, criteriaBuilder) ->
            criteriaBuilder
                    .or(
                            criteriaBuilder.isNull(root.get("value")),
                            criteriaBuilder.and(
                                    criteriaBuilder.greaterThanOrEqualTo(root.get("value"), a),
                                    criteriaBuilder.lessThanOrEqualTo(root.get("value"), b)
                            )
                    );

but getting this SQL in logs:

            user0_.value is null 
            or user0_.value>=a 
            and user0_.value<=b

that is not what I need. How to fix it?

littleAlien
  • 721
  • 2
  • 8
  • 20

0 Answers0