Package org.hibernate.query

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 interfaceNativeQuery<T>extendsQuery<T>,SynchronizeableQuery
Within the context of an activesession, 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 fromQuery, 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.

ANativeQuery may be obtained from theSession 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 automaticflush 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:

When the affected tables are not known to Hibernate, the behavior depends on whether Hibernate is operating in fully JPA-compliant mode.

  • In JPA-compliant mode,FlushModeType.AUTO specifies that the session should be flushed before execution of a native query when the affected tables are not known.
  • Otherwise, when Hibernate is not operating in JPA-compliant mode,AUTO specifies that the session isnot flushed before execution of a native query, unless the affected tables are known and Hibernate determines that a flush is required.
See Also: