Uploaded image for project: 'Spring Data Commons'
  1. Spring Data Commons
  2. DATACMNS-1319

Suggestion: change interpretation of Optionals as parameters in Spring Data JPA repositories interfaces

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      After this great idea: https://jira.spring.io/browse/DATACMNS-768 we are now capable of use methods such as 

       

      findByName(Optional<String> 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?

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              olivergierke Oliver Drotbohm
              Reporter:
              Miranda Marc
              Last updater:
              Spring Issues Spring Issues
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: