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

Add support for optional query method parameters. [DATACMNS-490] #958

spring-projects-issues opened this issue Apr 23, 2014 · 1 comment


Copy link

@spring-projects-issues spring-projects-issues commented Apr 23, 2014

Christoph Strobl opened DATACMNS-490 and commented

The use of Optional as method parameter type or @Param(optional=true) would potentially allow to create conditional query parts that only make their way into the final query in case a value is set.

List<Entity> findByNameOrDescription(@Param(optional=true) String name, Optional<String> description);


//SELECT * FROM Entity WHERE name = 'foo' AND description = 'bar'
findByNameOrDescription("foo", Optional.of("bar"));

//SELECT * FROM Entity WHERE name = 'foo'
findByNameOrDescription("foo", Optional.empty());

//SELECT * FROM Entity WHERE description = 'bar'
findByNameOrDescription(null, Optional.of("bar"));

Issue Links:

  • DATAMONGO-2486 Add support for optional query parameters in repository methods
    ("is duplicated by")
  • DATAJPA-209 Improve handling of null query method parameter values

4 votes, 5 watchers

Copy link

@spring-projects-issues spring-projects-issues commented Nov 13, 2019

Mark Paluch commented

We're using Optional<T> as a wrapper for nullability. Introducing another 'optional' flavor might cause more confusion and so I suggest to not explore that path any further


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