My understanding is, that with Spring data JPA I cannot have a query method to fetch all rows where a column equals a given non-null method parameter and use the same method to fetch all rows where this column is NULL when the method parameter is null.
Is that correct?
So I have to distinguish this in my JAVA code and I must use a separate query method explicitly asking for null values, like in the example below?
// Query methods
List<Something> findByParameter(Parameter parameter);
List<Something> result = new ArrayList<>();
if (parameter == null)
result = findByParameterIsNull();
result = findByParameter(parameter);
You are right.
A request has been made to support better handling of null parameters. https://jira.spring.io/browse/DATAJPA-121
In your case, i would advise you to write your repository implementation and to use a custom CriteriaQuery to handle your case.
Alternatively (not tested), you could use a @Query something like : (:parameter is null or parameter = :parameter)