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

First class suport for Optional [DATACMNS-603] #1066

Closed
spring-projects-issues opened this issue Nov 26, 2014 · 4 comments
Closed

First class suport for Optional [DATACMNS-603] #1066

spring-projects-issues opened this issue Nov 26, 2014 · 4 comments
Assignees
Labels
status: declined type: enhancement

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Nov 26, 2014

Lovro Pandžić opened DATACMNS-603 and commented

Add repository interfaces that have Optional return type for all methods that can possibly return null.
My main use case is when using Java 8 Optional


Issue Links:

  • DATACMNS-574 Change CrudRepository to return Optional<T> as return values instead of null reference or provide alternative base interface

  • DATACMNS-483 Support for wrapper types as return type on query methods

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 27, 2014

Oliver Drotbohm commented

Everything you need is in place:

  • Query methods can return Guava's and JDK 8 Optionals since the Evans release train
  • Methods declared on CrudRepository can be redeclared in a custom repository base class and work as expected:
@NoRepositoryBean
interface OptionalRepository<T, ID extends Serializable> extends Repository<T, ID> {

  Optional<T> findOne();

  …
}

For more information, see this blog post as well as this presentation.

Maybe we should add this more prominently in the reference docs?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 28, 2014

Lovro Pandžić commented

Does it also work with JpaRepository and QueryDslPredicateExecutor?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 28, 2014

Oliver Drotbohm commented

Depends on your definition. You can't use JpaRepository or QueryDslPredicateExecutor as supertype directly as they already declare the relevant methods without using Optional as return type. But if you add the methods of choice to your base repository and alter the return types from T to Optional<T>

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Mar 25, 2016

Christoph Strobl commented

Closed due to inactivity. Please feel free to reopen the issue and provide additional information

@spring-projects-issues spring-projects-issues added status: declined type: enhancement labels Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants