Interface Query<T>

Type Parameters:
T - The result type for selection queries or the target type for mutation statements.
All Superinterfaces:
CommonQueryContract, Query
All Known Subinterfaces:
MutationOrSelectionQuery, MutationQueryImplementor<T>, NativeQuery<T>, NativeQueryImplementor<R>, ProcedureCallImplementor<R>, QueryImplementor<T>, SelectionQuery<R>, SelectionQueryImplementor<R>

@Incubating public interface Query<T> extends CommonQueryContract
Within the context of an active session, an instance of this type represents an executable query, either:
  • a query written in HQL or native SQL,
  • a named query written in HQL or native SQL, or
  • a criteria query.

The subtype NativeQuery represents a query written in the native SQL dialect of the database.

This interface fills a very similar role to Query in JPA, acting as a bridge to client code written for older versions of the query APIs in JPA and Hibernate. Older versions did not carefully distinguish selection queries from insert, update, and delete mutation statements. Every instance of Query may logically be classified as one or the other.

Direct use of this interface to execute a query or statement is now discouraged. Instead, SelectionQuery should be used to execute a selection query, and MutationQuery should be used to execute a mutation statement. Therefore, operations of this interface which are only relevant to selection queries, or only relevant to mutation statements, are now marked as deprecated.

See Also:
API Note:
Like Query in JPA 4, this interface is now essentially redundant. Newly written code should always prefer SelectionQuery or MutationQuery.