Interface EntityQuery

All Superinterfaces:
ParametrizedQuery, QueryProvider

public interface EntityQuery extends ParametrizedQuery
An extension to ParametrizedQuery exposing query information about its inner structure such as whether constructor expressions (JPQL) are used or the default projection is used.

Entity Queries support derivation of count queries from the original query. They also can be used to rewrite the query using sorting and projection selection.

Since:
4.0
Author:
Jens Schauder, Diego Krupitza
  • Method Details

    • create

      static EntityQuery create(DeclaredQuery query, QueryEnhancerSelector selector)
      Parameters:
      query - must not be null.
      selector - must not be null.
      Returns:
      a new EntityQuery.
    • doWithEnhancer

      <T extends @Nullable Object> T doWithEnhancer(Function<QueryEnhancer,T> function)
      Apply a Function to the query enhancer used by this query.
      Type Parameters:
      T -
      Parameters:
      function - the callback function.
      Returns:
    • hasConstructorExpression

      boolean hasConstructorExpression()
      Returns whether the query is using a constructor expression.
      Since:
      1.10
    • isNative

      boolean isNative()
      Returns:
      whether the underlying query has at least one named parameter.
    • isDefaultProjection

      boolean isDefaultProjection()
      Returns whether the query uses the default projection, i.e. returns the main alias defined for the query.
    • usesPaging

      default boolean usesPaging()
      Returns:
      whether paging is implemented in the query itself, e.g. using SpEL expressions.
      Since:
      2.0.6
    • deriveCountQuery

      ParametrizedQuery deriveCountQuery(@Nullable String countQueryProjection)
      Creates a new IntrospectedQuery representing a count query, i.e. a query returning the number of rows to be expected from the original query, either derived from the query wrapped by this instance or from the information passed as arguments.
      Parameters:
      countQueryProjection - an optional return type for the query.
      Returns:
      a new IntrospectedQuery instance.
    • rewrite

      Rewrite the query using the given QueryEnhancer.QueryRewriteInformation into a sorted query or using a different projection. The rewritten query retains parameter binding characteristics.
      Parameters:
      rewriteInformation - query rewrite information (sorting, projection) to use.
      Returns:
      the rewritten query.