Annotation Interface Query


@Retention(RUNTIME) @Target(METHOD) public @interface Query
Defines the query string such as SQL, JPA-QL, Cypher etc. that should be executed.
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Defines the query to be executed when the annotated method is called.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Defines an additional query that counts the number of elements that are returned by the primary query.
  • Element Details

    • value

      String value

      Defines the query to be executed when the annotated method is called.

      If an application defines a repository method with @Query and supplies other forms of sorting (such as Sort) to that method, then it is the responsibility of the application to compose the query in such a way that an ORDER BY clause (or query language equivalent) can be validly appended. The Jakarta Data provider is not expected to parse query language that is provided by the application.

      Returns:
      the query to be executed when the annotated method is called.
    • count

      String count

      Defines an additional query that counts the number of elements that are returned by the primary query. This is used to compute the total elements and total pages for paginated repository queries that are annotated with @Query and return a Page or KeysetAwarePage. Slices do not use a counting query.

      The default value of empty string indicates that no counting query is provided. A counting query is unnecessary when pagination is performed with slices instead of pages and when pagination is not used at all.

      Returns:
      a query for counting the number of elements across all pages. Empty string indicates that no counting query is provided.
      Default:
      ""