Annotation Interface NativeQuery
@Retention(RUNTIME)
@Target({METHOD,ANNOTATION_TYPE})
@Documented
@Query(nativeQuery=true)
public @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
.
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionReturns the name of theNamedQuery
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 aQueryRewriter
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 forQuery.value()
.- Default:
- ""
-
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 orcountProjection()
query if any. Alias forQuery.countQuery()
.- Default:
- ""
-
countProjection
Defines the projection part of the count query that is generated for pagination. If neithercountQuery()
norcountProjection()
is configured we will derive the count query from the original query. Alias forQuery.countProjection()
.- Default:
- ""
-
name
The named query to be used. If not defined, aNamedQuery
with name of${domainClass}.${queryMethodName}
will be used. Alias forQuery.name()
.- Default:
- ""
-
countName
Returns the name of theNamedQuery
to be used to execute count queries when pagination is used. Will default to the named query name configured suffixed by.count
. Alias forQuery.countName()
.- Default:
- ""
-
queryRewriter
Define aQueryRewriter
that should be applied to the query string after the query is fully assembled. Alias forQuery.queryRewriter()
.- Default:
- org.springframework.data.jpa.repository.QueryRewriter.IdentityQueryRewriter.class
-
sqlResultSetMapping
String sqlResultSetMappingName of the@SqlResultSetMapping(name)
to apply for this query.- Default:
- ""
-