Skip to content

[Use Case]: Statically specify First/Limit at dev time so that singular return type can be valid on methods #532

Open
@njr-11

Description

@njr-11

As a ...

  • Application user/user of the configuration itself
  • API user (application developer)
  • SPI user (container or runtime developer)
  • Specification implementer

I need to be able to ...

statically specify a limit at development time

Which enables me to ...

write a repository method with a singular return type (Optional<MyEntity> or MyEntity).

Additional information

This is currently only possible (and awkwardly so) with Query by Method Name.

To allow it with @Query and parameter based queries (@Find), we can add First (proposed by Gavin in #530 (comment))

@Find @First
@OrderBy(value = _Employee.SALARY, descending = true)
@OrderBy(value = _Employee.ID)
Optional<Employee> highestPaid(String jobTitle);

The value would default to 1.

Reminder to update recommendations in NonUniqueResultException once we have this.

This is being proposed for after Jakarta Data version 1.0.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions