Top Description Inners Methods
org.hibernate.query

public Interface NativeQuery<T>

extends Query<T>, SynchronizeableQuery
Known Direct Subinterfaces
org.hibernate.query.sql.spi.NativeQueryImplementor
Imports
java.time.Instant, java.util.Calendar, .Collection, .Date, .Map, jakarta.persistence.AttributeConverter, .CacheRetrieveMode, .CacheStoreMode, .FlushModeType, .LockModeType, .Parameter, .TemporalType, jakarta.persistence.metamodel.SingularAttribute, org.hibernate.CacheMode, .FlushMode, .LockMode, .LockOptions, .MappingException, org.hibernate.metamodel.mapping.EntityMappingType, .PluralAttributeMapping, org.hibernate.metamodel.model.domain.BasicDomainType, org.hibernate.spi.NavigablePath, org.hibernate.transform.ResultTransformer, org.hibernate.type.BasicTypeReference

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:

A NativeQuery may be obtained from the org.hibernate.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:

Authors
Gavin King, Steve Ebersole
See Also
Query, SynchronizeableQuery, QueryProducer

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
NativeQuery.CollectionReturn

Allows access to further control how collection returns are mapped back from result sets.

public static interface
NativeQuery.FetchReturn

Allows access to further control how join fetch returns are mapped back from result sets.

public static interface
public static interface
NativeQuery.ResultNode

Simple unification interface for all returns from the various addXYZ() methods.

public static interface
NativeQuery.ReturnableResultNode

A ResultNode which can be a query result.

public static interface
NativeQuery.ReturnProperty

Allows access to further control how properties within a root or join fetch are mapped back from the result set.

public static interface
NativeQuery.RootReturn

Allows access to further control how root returns are mapped back from result sets.

Method Summary

Modifier and TypeMethod and Description
public NativeQuery<T>

Returns:

this, for method chaining
addAttributeResult
(String columnAlias, Class<T> entityJavaType, String attributePath)

Defines a result based on a specified attribute.

public NativeQuery<T>

Returns:

this, for method chaining
addAttributeResult
(String columnAlias, String entityName, String attributePath)

Defines a result based on a specified attribute.

public NativeQuery<T>

Returns:

this, for method chaining
addAttributeResult
(String columnAlias, SingularAttribute<X, T> attribute)

Defines a result based on a specified attribute.

public NativeQuery<T>

Returns:

this, for method chaining
addEntity
(String
The entity name that is the root return of the query
entityName
)

Declare a "root" entity, without specifying an alias.

public NativeQuery<T>

Returns:

this, for method chaining
addEntity
(String
The SQL table alias
tableAlias
,
String
The entity name
entityName
)

Declare a "root" entity.

public NativeQuery<T>

Returns:

this, for method chaining
addEntity
(String
The SQL table alias
tableAlias
,
String
The entity name
entityName
,
LockMode
The lock mode for this return.
lockMode
)

Declare a "root" entity, specifying a lock mode.

public NativeQuery<T>

Returns:

this, for method chaining
addEntity
(Class<T>
The java type of the entity to add as a root
entityType
)

Declare a "root" entity, without specifying an alias.

public NativeQuery<T>

Returns:

this, for method chaining
addEntity
(String
The SQL table alias
tableAlias
,
Class<T>
The java type of the entity to add as a root
entityType
)

Declare a "root" entity.

public NativeQuery<T>

Returns:

this, for method chaining
addEntity
(String
The SQL table alias
tableAlias
,
Class<T>
The entity Class
entityClass
,
LockMode
The lock mode for this return
lockMode
)

Declare a "root" entity, specifying a lock mode.

public NativeQuery.FetchReturn

Returns:

The return config object for further control.
addFetch
(String
The SQL table alias for the data to be mapped to this fetch.
tableAlias
,
String
Identify the table alias of the owner of this association. Should match the alias of a previously added root or fetch.
ownerTableAlias
,
String
The name of the property being join fetched.
joinPropertyName
)

Declare a join fetch result.

public <J> NativeQuery.InstantiationResultNode<J>
addInstantiation(Class<J> targetJavaType)

public NativeQuery<T>

Returns:

this, for method chaining
addJoin
(String
The SQL table alias for the data to be mapped to this fetch.
tableAlias
,
String
The association path of form [owner-alias].[property-name].
path
)

Declare a join fetch result.

public NativeQuery<T>

Returns:

this, for method chaining
addJoin
(String
The SQL table alias for the data to be mapped to this fetch
tableAlias
,
String
Identify the table alias of the owner of this association. Should match the alias of a previously added root or fetch.
ownerTableAlias
,
String
The name of the property being join fetched.
joinPropertyName
)

Declare a join fetch result.

public NativeQuery<T>

Returns:

this, for method chaining
addJoin
(String
The SQL table alias for the data to be mapped to this fetch
tableAlias
,
String
The association path of form [owner-alias].[property-name].
path
,
LockMode
The lock mode for this return.
lockMode
)

Declare a join fetch result, specifying a lock mode.

public NativeQuery<T>
addQueryHint(String
The database specific query hint to add.
hint
)

Redeclares org.hibernate.query.Query.addQueryHint.

Add a database query hint to the SQL query.
public NativeQuery.RootReturn

Returns:

The return config object for further control.
addRoot
(String
The SQL table alias to map to this entity
tableAlias
,
String
The name of the entity
entityName
)

Add a new root return mapping, returning a RootReturn to allow further definition.

public NativeQuery.RootReturn

Returns:

The return config object for further control.
addRoot
(String
The SQL table alias to map to this entity
tableAlias
,
Class<T>
The java type of the entity
entityType
)

Add a new root return mapping, returning a RootReturn to allow further definition.

public NativeQuery<T>

Returns:

this, for method chaining
addScalar
(String
The column alias in the result set to be processed as a scalar result
columnAlias
)

Declare a scalar query result.

public NativeQuery<T>

Returns:

this, for method chaining
addScalar
(String
The column alias in the result set to be processed as a scalar result
columnAlias
,
BasicTypeReference<T>
The Hibernate type as which to treat the value.
type
)

Declare a scalar query result.

public NativeQuery<T>

Returns:

this, for method chaining
addScalar
(String
The column alias in the result set to be processed as a scalar result
columnAlias
,
BasicDomainType<J>
The Hibernate type as which to treat the value.
type
)

Declare a scalar query result.

public NativeQuery<T>

Returns:

this, for method chaining
addScalar
(String columnAlias, Class<T> javaType)

Declare a scalar query result using the specified result type.

public <C> NativeQuery<T>

Returns:

this, for method chaining
addScalar
(String columnAlias, Class<C>
The Java type expected by the converter as its "relational" type.
relationalJavaType
,
AttributeConverter<?, C>
The conversion to apply. Consumes the JDBC value based on relationalJavaType.
converter
)

Declare a scalar query result with an explicit conversion.

public <O, R> NativeQuery<T>

Returns:

this, for method chaining
addScalar
(String columnAlias, Class<O>
The Java type expected by the converter as its "object model" type.
domainJavaType
,
Class<R>
The Java type expected by the converter as its "relational model" type.
jdbcJavaType
,
AttributeConverter<O, R>
The conversion to apply. Consumes the JDBC value based on relationalJavaType.
converter
)

Declare a scalar query result with an explicit conversion.

public <C> NativeQuery<T>

Returns:

this, for method chaining
addScalar
(String columnAlias, Class<C>
The Java type expected by the converter as its "relational" type.
relationalJavaType
,
Class<? extends AttributeConverter<?, C>>
The conversion to apply. Consumes the JDBC value based on relationalJavaType.
converter
)

Declare a scalar query result with an explicit conversion.

public <O, R> NativeQuery<T>

Returns:

this, for method chaining
addScalar
(String columnAlias, Class<O>
The Java type expected by the converter as its "object model" type.
domainJavaType
,
Class<R>
The Java type expected by the converter as its "relational model" type.
jdbcJavaType
,
Class<? extends AttributeConverter<O, R>>
The conversion to apply. Consumes the JDBC value based on relationalJavaType.
converter
)

Declare a scalar query result with an explicit conversion.

public NativeQuery<T>
addSynchronizedEntityClass(Class<T>
The class of the entity.
entityClass
)

Redeclares org.hibernate.query.SynchronizeableQuery.addSynchronizedEntityClass.

Add all query spaces associated with the entity with the given type.
public NativeQuery<T>
addSynchronizedEntityName(String
The name of an entity.
entityName
)

Redeclares org.hibernate.query.SynchronizeableQuery.addSynchronizedEntityName.

Add all query spaces associated with the entity with the given names.
public NativeQuery<T>
addSynchronizedQuerySpace(String
The name of the query space, usually the name of a database table.
querySpace
)

Redeclares org.hibernate.query.SynchronizeableQuery.addSynchronizedQuerySpace.

Add a query space.
public LockMode
public LockModeType
getLockMode()

Redeclares org.hibernate.query.SelectionQuery.getLockMode, jakarta.persistence.Query.getLockMode.

Not applicable to native SQL queries, due to an unfortunate requirement of the JPA specification.
public LockOptions
getLockOptions()

Redeclares org.hibernate.query.Query.getLockOptions.

Obtains the LockOptions in effect for this query.
public NativeQuery<T>
setCacheable(boolean cacheable)

Redeclares org.hibernate.query.Query.setCacheable.

Enable/disable second level query (result) caching for this query.
public NativeQuery<T>
setCacheMode(CacheMode cacheMode)

Redeclares org.hibernate.query.Query.setCacheMode.

Set the current CacheMode in effect for this query.
public NativeQuery<T>
setCacheRegion(String cacheRegion)

Redeclares org.hibernate.query.Query.setCacheRegion.

Set the name of the cache region where query results should be cached (assuming isCacheable).
public NativeQuery<T>
public NativeQuery<T>
public NativeQuery<T>
setComment(String
The human-readable comment
comment
)

Redeclares org.hibernate.query.Query.setComment.

Set the comment for this query.
public NativeQuery<T>
setFetchSize(int
the fetch size hint
fetchSize
)

Redeclares org.hibernate.query.Query.setFetchSize.

Sets a JDBC fetch size hint for the query.
public NativeQuery<T>
setFirstResult(int
position of the first result, numbered from 0
startPosition
)

Redeclares org.hibernate.query.Query.setFirstResult.

Set the first row position to return from the query results.
public NativeQuery<T>
setFlushMode(FlushModeType
flush mode
flushMode
)

Redeclares org.hibernate.query.Query.setFlushMode.

Set the flush mode type to be used for the query execution.
public NativeQuery<T>
setHibernateFlushMode(FlushMode flushMode)

Redeclares org.hibernate.query.Query.setHibernateFlushMode.

Set the current FlushMode in effect for this query.
public NativeQuery<T>
public NativeQuery<T>
setHint(String
name of property or hint
hintName
,
Object
value for the property or hint
value
)

Redeclares org.hibernate.query.Query.setHint.

Set a query property or hint.
public NativeQuery<T>
setLockMode(String
A query alias
alias
,
LockMode
The lock mode to apply
lockMode
)

Redeclares org.hibernate.query.Query.setLockMode.

Not applicable to native SQL queries.
public NativeQuery<T>
setLockMode(LockModeType
lock mode
lockMode
)

Redeclares org.hibernate.query.Query.setLockMode.

Not applicable to native SQL queries, due to an unfortunate requirement of the JPA specification.
public NativeQuery<T>
setLockOptions(LockOptions
The lock options to apply to the query.
lockOptions
)

Redeclares org.hibernate.query.Query.setLockOptions.

Apply the given lock options to this query.
public NativeQuery<T>
setMaxResults(int
maximum number of results to retrieve
maxResult
)

Redeclares org.hibernate.query.Query.setMaxResults.

Set the max number of rows requested for the query results.
public NativeQuery<T>
setParameter(String
parameter name
name
,
Object
parameter value
value
)

Redeclares org.hibernate.query.Query.setParameter.

Bind the given argument to a named query parameter.
public <P> NativeQuery<T>
setParameter(String name, P val, Class<P> type)

Redeclares org.hibernate.query.Query.setParameter.

Bind the given argument to a named query parameter using the given Class reference to attempt to determine the BindableType to use.
public <P> NativeQuery<T>
setParameter(String name, P val, BindableType<P> type)

Redeclares org.hibernate.query.Query.setParameter.

Bind the given argument to a named query parameter using the given BindableType.
public NativeQuery<T>
setParameter(String name, Instant value, TemporalType temporalType)

Redeclares org.hibernate.query.Query.setParameter.

Bind an Instant value to the named query parameter using just the portion indicated by the given TemporalType.
public NativeQuery<T>
setParameter(String
parameter name
name
,
Calendar
parameter value
value
,
TemporalType
temporal type
temporalType
)

Redeclares org.hibernate.query.Query.setParameter.

jakarta.persistence.Query override
public NativeQuery<T>
setParameter(String
parameter name
name
,
Date
parameter value
value
,
TemporalType
temporal type
temporalType
)

Redeclares org.hibernate.query.Query.setParameter.

jakarta.persistence.Query override
public NativeQuery<T>
setParameter(int
position
position
,
Object
parameter value
value
)

Redeclares org.hibernate.query.Query.setParameter.

Bind the given argument to an ordinal query parameter.
public <P> NativeQuery<T>
setParameter(int position, P val, Class<P> type)

Redeclares org.hibernate.query.Query.setParameter.

Bind the given argument to an ordinal query parameter using the given Class reference to attempt to determine the BindableType to use.
public <P> NativeQuery<T>
setParameter(int position, P val, BindableType<P> type)

Redeclares org.hibernate.query.Query.setParameter.

Bind the given argument to an ordinal query parameter using the given BindableType.
public NativeQuery<T>
setParameter(int position, Instant value, TemporalType temporalType)

Redeclares org.hibernate.query.Query.setParameter.

Bind an Instant value to the ordinal query parameter using just the portion indicated by the given TemporalType.
public NativeQuery<T>
setParameter(int
position
position
,
Calendar
parameter value
value
,
TemporalType
temporal type
temporalType
)

Redeclares org.hibernate.query.Query.setParameter.

jakarta.persistence.Query override
public NativeQuery<T>
setParameter(int
position
position
,
Date
parameter value
value
,
TemporalType
temporal type
temporalType
)

Redeclares org.hibernate.query.Query.setParameter.

jakarta.persistence.Query override
public <P> NativeQuery<T>
setParameter(QueryParameter<P>
the query parameter memento
parameter
,
P
the argument, which might be null
val
)

Redeclares org.hibernate.query.Query.setParameter.

Bind an argument to the query parameter represented by the given QueryParameter.
public <P> NativeQuery<T>
setParameter(QueryParameter<P>
the query parameter memento
parameter
,
P
the argument, which might be null
val
,
Class<P>
a BindableType representing the type of the parameter
type
)

Redeclares org.hibernate.query.Query.setParameter.

Bind an argument to the query parameter represented by the given QueryParameter using the given Class reference to attempt to determine the BindableType to use.
public <P> NativeQuery<T>
setParameter(QueryParameter<P>
the query parameter memento
parameter
,
P
the argument, which might be null
val
,
BindableType<P>
an BindableType representing the type of the parameter
type
)

Redeclares org.hibernate.query.Query.setParameter.

Bind an argument to the query parameter represented by the given QueryParameter using the given BindableType.
public <P> NativeQuery<T>
setParameter(Parameter<P>
parameter object
param
,
P
parameter value
value
)

Redeclares org.hibernate.query.Query.setParameter.

jakarta.persistence.Query override
public NativeQuery<T>
setParameter(Parameter<Calendar>
parameter object
param
,
Calendar
parameter value
value
,
TemporalType
temporal type
temporalType
)

Redeclares org.hibernate.query.Query.setParameter.

jakarta.persistence.Query override
public NativeQuery<T>
setParameter(Parameter<Date>
parameter object
param
,
Date
parameter value
value
,
TemporalType
temporal type
temporalType
)

Redeclares org.hibernate.query.Query.setParameter.

jakarta.persistence.Query override
public NativeQuery<T>
setParameterList(String name, Collection<E> values)

Redeclares org.hibernate.query.Query.setParameterList.

Bind multiple arguments to a named query parameter.
public <P> NativeQuery<T>
setParameterList(String name, Collection<? extends P> values, Class<P> type)

Redeclares org.hibernate.query.Query.setParameterList.

Bind multiple arguments to a named query parameter using the given Class reference to attempt to determine the BindableType to use.
public <P> NativeQuery<T>
setParameterList(String name, Collection<? extends P> values, BindableType<P> type)

Redeclares org.hibernate.query.Query.setParameterList.

Bind multiple arguments to a named query parameter using the given BindableType.
public NativeQuery<T>
setParameterList(String name, Object[] values)

Redeclares org.hibernate.query.Query.setParameterList.

Bind multiple arguments to a named query parameter.
public <P> NativeQuery<T>
setParameterList(String name, P[] values, Class<P> type)

Redeclares org.hibernate.query.Query.setParameterList.

Bind multiple arguments to a named query parameter using the given Class reference to attempt to determine the BindableType to use.
public <P> NativeQuery<T>
setParameterList(String name, P[] values, BindableType<P> type)

Redeclares org.hibernate.query.Query.setParameterList.

Bind multiple arguments to a named query parameter using the given BindableType.
public NativeQuery<T>
setParameterList(int position, Collection<E> values)

Redeclares org.hibernate.query.Query.setParameterList.

Bind multiple arguments to an ordinal query parameter.
public <P> NativeQuery<T>
setParameterList(int position, Collection<? extends P> values, Class<P> type)

Redeclares org.hibernate.query.Query.setParameterList.

Bind multiple arguments to an ordinal query parameter using the given Class reference to attempt to determine the BindableType to use.
public <P> NativeQuery<T>
setParameterList(int position, Collection<? extends P> values, BindableType<P> javaType)

Redeclares org.hibernate.query.Query.setParameterList.

Bind multiple arguments to an ordinal query parameter using the given BindableType.
public NativeQuery<T>
setParameterList(int position, Object[] values)

Redeclares org.hibernate.query.Query.setParameterList.

Bind multiple arguments to an ordinal query parameter.
public <P> NativeQuery<T>
setParameterList(int position, P[] values, Class<P> javaType)

Redeclares org.hibernate.query.Query.setParameterList.

Bind multiple arguments to an ordinal query parameter using the given Class reference to attempt to determine the BindableType to use.
public <P> NativeQuery<T>
setParameterList(int position, P[] values, BindableType<P> javaType)

Redeclares org.hibernate.query.Query.setParameterList.

Bind multiple arguments to an ordinal query parameter using the given BindableType.
public <P> NativeQuery<T>
setParameterList(QueryParameter<P>
the parameter memento
parameter
,
Collection<? extends P>
a collection of arguments
values
)

Redeclares org.hibernate.query.Query.setParameterList.

Bind multiple arguments to the query parameter represented by the given QueryParameter.
public <P> NativeQuery<T>
setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, Class<P> javaType)

Redeclares org.hibernate.query.Query.setParameterList.

Bind multiple arguments to the query parameter represented by the given QueryParameter using the given Class reference to attempt to determine the BindableType to use.
public <P> NativeQuery<T>
setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, BindableType<P> type)

Redeclares org.hibernate.query.Query.setParameterList.

Bind multiple arguments to the query parameter represented by the given QueryParameter, inferring the BindableType.
public <P> NativeQuery<T>
setParameterList(QueryParameter<P>
the parameter memento
parameter
,
P[]
a collection of arguments
values
)

Redeclares org.hibernate.query.Query.setParameterList.

Bind multiple arguments to the query parameter represented by the given QueryParameter.
public <P> NativeQuery<T>
setParameterList(QueryParameter<P> parameter, P[] values, Class<P> javaType)

Redeclares org.hibernate.query.Query.setParameterList.

Bind multiple arguments to the query parameter represented by the given QueryParameter using the given Class reference to attempt to determine the BindableType to use.
public <P> NativeQuery<T>
setParameterList(QueryParameter<P> parameter, P[] values, BindableType<P> type)

Redeclares org.hibernate.query.Query.setParameterList.

Bind multiple arguments to the query parameter represented by the given QueryParameter, inferring the BindableType.
public NativeQuery<T>
setProperties(Object
any JavaBean or POJO
bean
)

Redeclares org.hibernate.query.Query.setProperties.

Bind the property values of the given bean to named parameters of the query, matching property names with parameter names and mapping property types to Hibernate types using heuristics.
public NativeQuery<T>
setProperties(Map<K, V>
a Map of names to arguments
bean
)

Redeclares org.hibernate.query.Query.setProperties.

Bind the values of the given Map for each named parameters of the query, matching key names with parameter names and mapping value types to Hibernate types using heuristics.
public NativeQuery<T>
setReadOnly(boolean
true indicates that entities and proxies loaded by the query are to be put in read-only mode; false indicates that entities and proxies loaded by the query will be put in modifiable mode
readOnly
)

Redeclares org.hibernate.query.Query.setReadOnly.

Set the read-only/modifiable mode for entities and proxies loaded by this Query.
public NativeQuery<T>
public <S> NativeQuery<S>
public NativeQuery<T>
setTimeout(int
the timeout in seconds
timeout
)

Redeclares org.hibernate.query.Query.setTimeout.

Set the query timeout in seconds.
public <R> NativeQuery<R>
Inherited from org.hibernate.query.Query:
applyFetchGraphapplyGraphapplyLoadGraphdisableFetchProfileenableFetchProfileexecuteUpdategetCommentgetParameterMetadatagetQueryOptionsgetQueryStringgetResultListgetResultStreamgetSessiongetSingleResultlistscrollscrollsetEntityGraphsetOrdersetOrdersetPagestreamuniqueResultuniqueResultOptional
Inherited from org.hibernate.query.SynchronizeableQuery:
getSynchronizedQuerySpaces