Interface NativeQuery<T>

All Superinterfaces:
CommonQueryContract, MutationQuery, Query, Query<T>, SelectionQuery<T>, SynchronizeableQuery, TypedQuery<T>
All Known Subinterfaces:
NativeQueryImplementor<R>
All Known Implementing Classes:
NativeQueryImpl

public interface NativeQuery<T> extends Query<T>, SynchronizeableQuery
Within the context of an active session, an instance of this type represents an executable query written in the native SQL dialect of the underlying database. Since Hibernate does not actually understand SQL, it often requires some help in interpreting the semantics of a native SQL query.

Along with the operations inherited from Query, this interface provides control over:

  • mapping the result set of the native SQL query, and
  • synchronization of the database with state held in memory before execution of the query, via automatic flushing of the session.

A NativeQuery may be obtained from the Session by calling:

A result set mapping may be specified by:

The third option is a legacy of much older versions of Hibernate and is currently disfavored.

To determine if an automatic flush is required before execution of the query, Hibernate must know which tables affect the query result set. JPA provides no standard way to do this. Instead, this information may be provided via:

See Also: