Annotation Interface NativeQuery


Annotation to declare native queries directly on repository query methods.

Specifically @NativeQuery is a composed annotation that acts as a shortcut for @Query(nativeQuery = true) for most attributes.

This annotation defines sqlResultSetMapping to apply JPA SQL ResultSet mapping for native queries. Make sure to use the corresponding return type as defined in @SqlResultSetMapping. When using named native queries, define SQL result set mapping through @NamedNativeQuery(resultSetMapping=…) as named queries do not accept sqlResultSetMapping.

Since:
3.4
Author:
Danny van den Elshout, Mark Paluch
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Returns the name of the NamedQuery to be used to execute count queries when pagination is used.
    Defines the projection part of the count query that is generated for pagination.
    Defines a special count query that shall be used for pagination queries to look up the total number of elements for a page.
    The named query to be used.
    Class<? extends QueryRewriter>
    Define a QueryRewriter that should be applied to the query string after the query is fully assembled.
    Name of the @SqlResultSetMapping(name) to apply for this query.
    Defines the native query to be executed when the annotated method is called.
  • Element Details

    • value

      Defines the native query to be executed when the annotated method is called. Alias for Query.value().
      Default:
      ""
    • countQuery

      @AliasFor(annotation=Query.class) String countQuery
      Defines a special count query that shall be used for pagination queries to look up the total number of elements for a page. If none is configured we will derive the count query from the original query or countProjection() query if any. Alias for Query.countQuery().
      Default:
      ""
    • countProjection

      @AliasFor(annotation=Query.class) String countProjection
      Defines the projection part of the count query that is generated for pagination. If neither countQuery() nor countProjection() is configured we will derive the count query from the original query. Alias for Query.countProjection().
      Default:
      ""
    • name

      The named query to be used. If not defined, a NamedQuery with name of ${domainClass}.${queryMethodName} will be used. Alias for Query.name().
      Default:
      ""
    • countName

      @AliasFor(annotation=Query.class) String countName
      Returns the name of the NamedQuery to be used to execute count queries when pagination is used. Will default to the named query name configured suffixed by .count. Alias for Query.countName().
      Default:
      ""
    • queryRewriter

      @AliasFor(annotation=Query.class) Class<? extends QueryRewriter> queryRewriter
      Define a QueryRewriter that should be applied to the query string after the query is fully assembled. Alias for Query.queryRewriter().
      Default:
      org.springframework.data.jpa.repository.QueryRewriter.IdentityQueryRewriter.class
    • sqlResultSetMapping

      String sqlResultSetMapping
      Name of the @SqlResultSetMapping(name) to apply for this query.
      Default:
      ""