I have this spring JPA query:
Optional<List<Result>> findAllByAvailabilityAndItemCategoryAndIdLessThanOrderByIdDesc(
String availability, String category, long cursor, Pageable pageable
);
When passing a null
value as one of the parameters, JPA looks for the actual null value in the database.
Example:
repository.findAllByAvailabilityAndItemCategoryAndIdLessThanOrderByIdDesc("avail",null,0, pageableObj);
In this case, Spring will return the fields where category
is null
and match the rest of the criteria.
What I'd like to achieve is, when passing null
, I want Spring to kind of ignore it and return all the values for that specific field.
I know I can achieve this by writing a SQL @Query
above the function, but I want to know if there is no way of adding a condition check in the JPA query itself.