Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: change interpretation of Optionals as parameters in Spring Data JPA repositories interfaces [DATACMNS-1319] #1760

spring-projects-issues opened this issue May 16, 2018 · 0 comments


Copy link

@spring-projects-issues spring-projects-issues commented May 16, 2018

Marc opened DATACMNS-1319 and commented

After this great idea: we are now capable of use methods such as 


findByName(Optional name), and, for instance, sending directly from controller some parameters.  My problem is that I cannot understand why the decision of considering empty Optionals as SQL NULLs instead of no filtering. In previous case, I would have expected findByName(Optional.empty()) to return all names


Pros of using Optionals as "Not present"  in repositories: 

  • The purpose of Optional is making everything null safe. Null in that case is a value, and then can be passed without Optional if needed .
  • Makes very very easy to work with multiple filters better than projections
  • Makes very very very easy to work with optional criteria filters in controllers, and forward them down, without having to define custom queries

What do you think?

Issue Links:

  • DATAJPA-209 Improve handling of null query method parameter values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants