Package org.hibernate.query
Interface NativeQuery<T>
-
- All Superinterfaces:
CommonQueryContract
,Query
,Query<T>
,SynchronizeableQuery
,TypedQuery<T>
- All Known Subinterfaces:
NativeQueryImplementor<R>
public interface NativeQuery<T> extends Query<T>, SynchronizeableQuery
Represents a native (SQL) query. Allows the user to define certain aspects about its execution, such as:- result-set value mapping (see below)
-
Tables used via
addSynchronizedQuerySpace(java.lang.String)
,addSynchronizedEntityName(java.lang.String)
andSynchronizeableQuery.addSynchronizedEntityClass(java.lang.Class<?>)
. This allows Hibernate to know how to properly deal with auto-flush checking as well as cached query results if the results of the query are being cached.
- If this represents a named sql query, the mapping could be associated with the query as part of its metadata
-
A pre-defined (defined in metadata and named) mapping can be associated via
QueryProducer.createNativeQuery(String, String)
-
Defined locally per the various
addEntity(java.lang.String)
,addRoot(java.lang.String, java.lang.String)
,addJoin(java.lang.String, java.lang.String)
,addFetch(java.lang.String, java.lang.String, java.lang.String)
andaddScalar(java.lang.String)
methods
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
NativeQuery.CollectionReturn
static interface
NativeQuery.FetchReturn
Allows access to further control how join fetch returns are mapped back from result sets.static interface
NativeQuery.InstantiationResultNode<J>
static interface
NativeQuery.ResultNode
Simple unification interface for all returns from the various `#addXYZ` methods .static interface
NativeQuery.ReturnableResultNode
ResultNode which can be a query resultstatic interface
NativeQuery.ReturnProperty
Allows access to further control how properties within a root or join fetch are mapped back from the result set.static interface
NativeQuery.RootReturn
Allows access to further control how root returns are mapped back from result sets.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description NativeQuery<T>
addAttributeResult(String columnAlias, SingularAttribute<?,?> attribute)
Defines a result based on a specified attribute.NativeQuery<T>
addAttributeResult(String columnAlias, Class<?> entityJavaType, String attributePath)
Defines a result based on a specified attribute.NativeQuery<T>
addAttributeResult(String columnAlias, String entityName, String attributePath)
Defines a result based on a specified attribute.NativeQuery<T>
addEntity(Class<?> entityType)
Declare a "root" entity, without specifying an alias.NativeQuery<T>
addEntity(String entityName)
Declare a "root" entity, without specifying an alias.NativeQuery<T>
addEntity(String tableAlias, Class<?> entityType)
Declare a "root" entity.NativeQuery<T>
addEntity(String tableAlias, Class<?> entityClass, LockMode lockMode)
Declare a "root" entity, specifying a lock mode.NativeQuery<T>
addEntity(String tableAlias, String entityName)
Declare a "root" entity.NativeQuery<T>
addEntity(String tableAlias, String entityName, LockMode lockMode)
Declare a "root" entity, specifying a lock mode.NativeQuery.FetchReturn
addFetch(String tableAlias, String ownerTableAlias, String joinPropertyName)
Declare a join fetch result.<J> NativeQuery.InstantiationResultNode<J>
addInstantiation(Class<J> targetJavaType)
NativeQuery<T>
addJoin(String tableAlias, String path)
Declare a join fetch result.NativeQuery<T>
addJoin(String tableAlias, String ownerTableAlias, String joinPropertyName)
Declare a join fetch result.NativeQuery<T>
addJoin(String tableAlias, String path, LockMode lockMode)
Declare a join fetch result, specifying a lock mode.NativeQuery<T>
addQueryHint(String hint)
Add a DB query hint to the SQL.NativeQuery.RootReturn
addRoot(String tableAlias, Class entityType)
Add a new root return mapping, returning aNativeQuery.RootReturn
to allow further definition.NativeQuery.RootReturn
addRoot(String tableAlias, String entityName)
Add a new root return mapping, returning aNativeQuery.RootReturn
to allow further definition.NativeQuery<T>
addScalar(String columnAlias)
Declare a scalar query result.NativeQuery<T>
addScalar(String columnAlias, Class<?> javaType)
Declare a scalar query result using the specified result type.<C> NativeQuery<T>
addScalar(String columnAlias, Class<C> relationalJavaType, AttributeConverter<?,C> converter)
Declare a scalar query result with an explicit conversion<C> NativeQuery<T>
addScalar(String columnAlias, Class<C> relationalJavaType, Class<? extends AttributeConverter<?,C>> converter)
Declare a scalar query result with an explicit conversion<O,R>
NativeQuery<T>addScalar(String columnAlias, Class<O> domainJavaType, Class<R> jdbcJavaType, AttributeConverter<O,R> converter)
Declare a scalar query result with an explicit conversion<O,R>
NativeQuery<T>addScalar(String columnAlias, Class<O> domainJavaType, Class<R> jdbcJavaType, Class<? extends AttributeConverter<O,R>> converter)
Declare a scalar query result with an explicit conversionNativeQuery<T>
addScalar(String columnAlias, BasicDomainType<?> type)
Declare a scalar query result.NativeQuery<T>
addScalar(String columnAlias, BasicTypeReference<?> type)
Declare a scalar query result.NativeQuery<T>
addSynchronizedEntityClass(Class<?> entityClass)
Adds an entity for (a) auto-flush checking and (b) query result cache invalidation checking.NativeQuery<T>
addSynchronizedEntityName(String entityName)
Adds an entity name for (a) auto-flush checking and (b) query result cache invalidation checking.NativeQuery<T>
addSynchronizedQuerySpace(String querySpace)
Adds a query space.NativeQuery<T>
setCacheable(boolean cacheable)
Enable/disable second level query (result) caching for this query.NativeQuery<T>
setCacheMode(CacheMode cacheMode)
(Re)set the current CacheMode in effect for this query.NativeQuery<T>
setCacheRegion(String cacheRegion)
Set the name of the cache region where query results should be cached (if cached at all).NativeQuery<T>
setComment(String comment)
Set the comment for this query.NativeQuery<T>
setFetchSize(int fetchSize)
Sets a JDBC fetch size hint for the query.NativeQuery<T>
setFirstResult(int startPosition)
NativeQuery<T>
setFlushMode(FlushModeType flushMode)
NativeQuery<T>
setHibernateFlushMode(FlushMode flushMode)
(Re)set the current FlushMode in effect for this query.NativeQuery<T>
setHint(String hintName, Object value)
NativeQuery<T>
setLockMode(LockModeType lockMode)
NativeQuery<T>
setLockMode(String alias, LockMode lockMode)
Set the LockMode to use for specific alias (as defined in the query's FROM clause).NativeQuery<T>
setLockOptions(LockOptions lockOptions)
Set the lock options for the query.NativeQuery<T>
setMaxResults(int maxResult)
NativeQuery<T>
setParameter(int position, Object value)
Bind a positional query parameter using its inferred Type.NativeQuery<T>
setParameter(int position, Object val, TemporalType temporalType)
Bind a positional query parameter as some form of date/time using the indicated temporal-type.NativeQuery<T>
setParameter(int position, Instant value, TemporalType temporalType)
NativeQuery<T>
setParameter(int position, LocalDateTime value, TemporalType temporalType)
NativeQuery<T>
setParameter(int position, OffsetDateTime value, TemporalType temporalType)
NativeQuery<T>
setParameter(int position, ZonedDateTime value, TemporalType temporalType)
NativeQuery<T>
setParameter(int position, Calendar value, TemporalType temporalType)
NativeQuery<T>
setParameter(int position, Date value, TemporalType temporalType)
<P> NativeQuery<T>
setParameter(int position, P val, AllowableParameterType<P> type)
Bind a value to a JDBC-style query parameter.<P> NativeQuery<T>
setParameter(int position, P val, BasicTypeReference<P> type)
Bind a value to a JDBC-style query parameter.NativeQuery<T>
setParameter(Parameter<Instant> param, Instant value, TemporalType temporalType)
NativeQuery<T>
setParameter(Parameter<LocalDateTime> param, LocalDateTime value, TemporalType temporalType)
NativeQuery<T>
setParameter(Parameter<OffsetDateTime> param, OffsetDateTime value, TemporalType temporalType)
NativeQuery<T>
setParameter(Parameter<ZonedDateTime> param, ZonedDateTime value, TemporalType temporalType)
NativeQuery<T>
setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType)
NativeQuery<T>
setParameter(Parameter<Date> param, Date value, TemporalType temporalType)
<P> NativeQuery<T>
setParameter(Parameter<P> param, P value)
NativeQuery<T>
setParameter(String name, Object value)
Bind a named query parameter using its inferred Type.NativeQuery<T>
setParameter(String name, Object val, TemporalType temporalType)
Bind a named query parameter as some form of date/time using the indicated temporal-type.NativeQuery<T>
setParameter(String name, Instant value, TemporalType temporalType)
NativeQuery<T>
setParameter(String name, LocalDateTime value, TemporalType temporalType)
NativeQuery<T>
setParameter(String name, OffsetDateTime value, TemporalType temporalType)
NativeQuery<T>
setParameter(String name, ZonedDateTime value, TemporalType temporalType)
NativeQuery<T>
setParameter(String name, Calendar value, TemporalType temporalType)
NativeQuery<T>
setParameter(String name, Date value, TemporalType temporalType)
<P> NativeQuery<T>
setParameter(String name, P val, AllowableParameterType<P> type)
Bind a named query parameter using the supplied Type<P> NativeQuery<T>
setParameter(String name, P val, BasicTypeReference<P> type)
Bind a named query parameter using the supplied Type<P> NativeQuery<T>
setParameter(QueryParameter<P> parameter, P val)
Bind a query parameter using its inferred Type.<P> NativeQuery<T>
setParameter(QueryParameter<P> parameter, P val, TemporalType temporalType)
Bind a query parameter as some form of date/time using the indicated temporal-type.<P> NativeQuery<T>
setParameter(QueryParameter<P> parameter, P val, AllowableParameterType<P> type)
Bind a query parameter using the supplied Type<P> NativeQuery<T>
setParameter(QueryParameter<P> parameter, P val, BasicTypeReference<P> type)
Bind a query parameter using the supplied TypeNativeQuery<T>
setParameterList(int position, Object[] values)
Bind multiple values to a named query parameter.NativeQuery<T>
setParameterList(int position, Object[] values, AllowableParameterType<?> type)
Bind multiple values to a named query parameter.NativeQuery<T>
setParameterList(int position, Collection<?> values)
Bind multiple values to a positional query parameter.<P> NativeQuery<T>
setParameterList(int position, Collection<? extends P> values, Class<P> type)
Bind multiple values to a positional query parameter.<P> NativeQuery<T>
setParameterList(int position, Collection<? extends P> values, AllowableParameterType<P> type)
Bind multiple values to a positional query parameter.NativeQuery<T>
setParameterList(String name, Object[] values)
Bind multiple values to a named query parameter.NativeQuery<T>
setParameterList(String name, Object[] values, AllowableParameterType<?> type)
Bind multiple values to a named query parameter.NativeQuery<T>
setParameterList(String name, Collection<?> values)
Bind multiple values to a named query parameter.<P> NativeQuery<T>
setParameterList(String name, Collection<? extends P> values, Class<P> type)
Bind multiple values to a named query parameter.<P> NativeQuery<T>
setParameterList(String name, Collection<? extends P> values, AllowableParameterType<P> type)
Bind multiple values to a named query parameter.<P> NativeQuery<T>
setParameterList(QueryParameter<P> parameter, Collection<P> values)
Bind multiple values to a query parameter using its inferred Type.NativeQuery<T>
setProperties(Object bean)
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.NativeQuery<T>
setProperties(Map bean)
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.NativeQuery<T>
setReadOnly(boolean readOnly)
Set the read-only/modifiable mode for entities and proxies loaded by this Query.NativeQuery<T>
setResultListTransformer(ResultListTransformer transformer)
NativeQuery<T>
setResultTransformer(ResultTransformer transformer)
NativeQuery<T>
setTimeout(int timeout)
Set the query timeout in seconds.NativeQuery<T>
setTupleTransformer(TupleTransformer<T> transformer)
-
Methods inherited from interface org.hibernate.query.CommonQueryContract
getCacheMode, getCacheRegion, getFetchSize, getHibernateFlushMode, getTimeout, isCacheable, isReadOnly
-
Methods inherited from interface jakarta.persistence.Query
executeUpdate, getFirstResult, getFlushMode, getHints, getLockMode, getMaxResults, getParameter, getParameter, getParameter, getParameter, getParameters, getParameterValue, getParameterValue, getParameterValue, isBound, unwrap
-
Methods inherited from interface org.hibernate.query.Query
applyFetchGraph, applyGraph, applyLoadGraph, getComment, getLockOptions, getParameterMetadata, getQueryOptions, getQueryString, getResultList, getResultStream, getSession, getSingleResult, list, scroll, scroll, stream, uniqueResult, uniqueResultOptional
-
Methods inherited from interface org.hibernate.query.SynchronizeableQuery
getSynchronizedQuerySpaces
-
-
-
-
Method Detail
-
addScalar
NativeQuery<T> addScalar(String columnAlias)
Declare a scalar query result. Hibernate will attempt to automatically detect the underlying type. Functions like<return-scalar/>
inhbm.xml
orColumnResult
in annotations- Parameters:
columnAlias
- The column alias in the result-set to be processed as a scalar result- Returns:
this
, for method chaining
-
addScalar
NativeQuery<T> addScalar(String columnAlias, BasicTypeReference<?> type)
Declare a scalar query result. Functions like<return-scalar/>
inhbm.xml
orColumnResult
in annotations- Parameters:
columnAlias
- The column alias in the result-set to be processed as a scalar resulttype
- The Hibernate type as which to treat the value.- Returns:
this
, for method chaining
-
addScalar
NativeQuery<T> addScalar(String columnAlias, BasicDomainType<?> type)
Declare a scalar query result. Functions like<return-scalar/>
inhbm.xml
orColumnResult
in annotations- Parameters:
columnAlias
- The column alias in the result-set to be processed as a scalar resulttype
- The Hibernate type as which to treat the value.- Returns:
this
, for method chaining
-
addScalar
NativeQuery<T> addScalar(String columnAlias, Class<?> javaType)
Declare a scalar query result using the specified result type. Hibernate will implicitly determine an appropriate conversion, if it can. Otherwise an exception will be thrown- Returns:
this
, for method chaining- Since:
- 6.0
-
addScalar
<C> NativeQuery<T> addScalar(String columnAlias, Class<C> relationalJavaType, AttributeConverter<?,C> converter)
Declare a scalar query result with an explicit conversion- Parameters:
relationalJavaType
- The Java type expected by the converter as its "relational" type.converter
- The conversion to apply. Consumes the JDBC value based on `relationalJavaType`.- Returns:
this
, for method chaining- Since:
- 6.0
-
addScalar
<O,R> NativeQuery<T> addScalar(String columnAlias, Class<O> domainJavaType, Class<R> jdbcJavaType, AttributeConverter<O,R> converter)
Declare a scalar query result with an explicit conversion- Parameters:
jdbcJavaType
- The Java type expected by the converter as its "relational model" type.domainJavaType
- The Java type expected by the converter as its "object model" type.converter
- The conversion to apply. Consumes the JDBC value based on `relationalJavaType`.- Returns:
this
, for method chaining- Since:
- 6.0
-
addScalar
<C> NativeQuery<T> addScalar(String columnAlias, Class<C> relationalJavaType, Class<? extends AttributeConverter<?,C>> converter)
Declare a scalar query result with an explicit conversion- Parameters:
relationalJavaType
- The Java type expected by the converter as its "relational" type.converter
- The conversion to apply. Consumes the JDBC value based on `relationalJavaType`.- Returns:
this
, for method chaining- Since:
- 6.0
-
addScalar
<O,R> NativeQuery<T> addScalar(String columnAlias, Class<O> domainJavaType, Class<R> jdbcJavaType, Class<? extends AttributeConverter<O,R>> converter)
Declare a scalar query result with an explicit conversion- Parameters:
jdbcJavaType
- The Java type expected by the converter as its "relational model" type.domainJavaType
- The Java type expected by the converter as its "object model" type.converter
- The conversion to apply. Consumes the JDBC value based on `jdbcJavaType`.- Returns:
this
, for method chaining- Since:
- 6.0
-
addInstantiation
<J> NativeQuery.InstantiationResultNode<J> addInstantiation(Class<J> targetJavaType)
-
addAttributeResult
NativeQuery<T> addAttributeResult(String columnAlias, Class<?> entityJavaType, String attributePath)
Defines a result based on a specified attribute. Differs from adding a scalar in that any conversions or other semantics defined on the attribute are automatically applied to the mapping- Returns:
this
, for method chaining- Since:
- 6.0
-
addAttributeResult
NativeQuery<T> addAttributeResult(String columnAlias, String entityName, String attributePath)
Defines a result based on a specified attribute. Differs from adding a scalar in that any conversions or other semantics defined on the attribute are automatically applied to the mapping- Returns:
this
, for method chaining- Since:
- 6.0
-
addAttributeResult
NativeQuery<T> addAttributeResult(String columnAlias, SingularAttribute<?,?> attribute)
Defines a result based on a specified attribute. Differs from adding a scalar in that any conversions or other semantics defined on the attribute are automatically applied to the mapping. This form accepts the JPA Attribute mapping describing the attribute- Returns:
this
, for method chaining- Since:
- 6.0
-
addRoot
NativeQuery.RootReturn addRoot(String tableAlias, String entityName)
Add a new root return mapping, returning aNativeQuery.RootReturn
to allow further definition.- Parameters:
tableAlias
- The SQL table alias to map to this entityentityName
- The name of the entity.- Returns:
- The return config object for further control.
- Since:
- 3.6
-
addRoot
NativeQuery.RootReturn addRoot(String tableAlias, Class entityType)
Add a new root return mapping, returning aNativeQuery.RootReturn
to allow further definition.- Parameters:
tableAlias
- The SQL table alias to map to this entityentityType
- The java type of the entity.- Returns:
- The return config object for further control.
- Since:
- 3.6
-
addEntity
NativeQuery<T> addEntity(String entityName)
Declare a "root" entity, without specifying an alias. The expectation here is that the table alias is the same as the unqualified entity name UseaddRoot(java.lang.String, java.lang.String)
if you need further control of the mapping- Parameters:
entityName
- The entity name that is the root return of the query.- Returns:
this
, for method chaining
-
addEntity
NativeQuery<T> addEntity(String tableAlias, String entityName)
Declare a "root" entity.- Parameters:
tableAlias
- The SQL table aliasentityName
- The entity name- Returns:
this
, for method chaining
-
addEntity
NativeQuery<T> addEntity(String tableAlias, String entityName, LockMode lockMode)
Declare a "root" entity, specifying a lock mode.- Parameters:
tableAlias
- The SQL table aliasentityName
- The entity namelockMode
- The lock mode for this return.- Returns:
this
, for method chaining
-
addEntity
NativeQuery<T> addEntity(Class<?> entityType)
Declare a "root" entity, without specifying an alias. The expectation here is that the table alias is the same as the unqualified entity name- Parameters:
entityType
- The java type of the entity to add as a root- Returns:
this
, for method chaining
-
addEntity
NativeQuery<T> addEntity(String tableAlias, Class<?> entityType)
Declare a "root" entity.- Parameters:
tableAlias
- The SQL table aliasentityType
- The java type of the entity to add as a root- Returns:
this
, for method chaining
-
addEntity
NativeQuery<T> addEntity(String tableAlias, Class<?> entityClass, LockMode lockMode)
Declare a "root" entity, specifying a lock mode.- Parameters:
tableAlias
- The SQL table aliasentityClass
- The entity ClasslockMode
- The lock mode for this return.- Returns:
this
, for method chaining
-
addFetch
NativeQuery.FetchReturn addFetch(String tableAlias, String ownerTableAlias, String joinPropertyName)
Declare a join fetch result.- Parameters:
tableAlias
- The SQL table alias for the data to be mapped to this fetchownerTableAlias
- Identify the table alias of the owner of this association. Should match the alias of a previously added root or fetchjoinPropertyName
- The name of the property being join fetched.- Returns:
- The return config object for further control.
- Since:
- 3.6
-
addJoin
NativeQuery<T> addJoin(String tableAlias, String path)
Declare a join fetch result.- Parameters:
tableAlias
- The SQL table alias for the data to be mapped to this fetchpath
- The association path ([owner-alias].[property-name]).- Returns:
this
, for method chaining
-
addJoin
NativeQuery<T> addJoin(String tableAlias, String ownerTableAlias, String joinPropertyName)
Declare a join fetch result.- Parameters:
tableAlias
- The SQL table alias for the data to be mapped to this fetchownerTableAlias
- Identify the table alias of the owner of this association. Should match the alias of a previously added root or fetchjoinPropertyName
- The name of the property being join fetched.- Returns:
this
, for method chaining- Since:
- 3.6
-
addJoin
NativeQuery<T> addJoin(String tableAlias, String path, LockMode lockMode)
Declare a join fetch result, specifying a lock mode.- Parameters:
tableAlias
- The SQL table alias for the data to be mapped to this fetchpath
- The association path ([owner-alias].[property-name]).lockMode
- The lock mode for this return.- Returns:
this
, for method chaining
-
addSynchronizedQuerySpace
NativeQuery<T> addSynchronizedQuerySpace(String querySpace)
Description copied from interface:SynchronizeableQuery
Adds a query space.- Specified by:
addSynchronizedQuerySpace
in interfaceSynchronizeableQuery
- Parameters:
querySpace
- The query space to be auto-flushed for this query.- Returns:
this
, for method chaining
-
addSynchronizedEntityName
NativeQuery<T> addSynchronizedEntityName(String entityName) throws MappingException
Description copied from interface:SynchronizeableQuery
Adds an entity name for (a) auto-flush checking and (b) query result cache invalidation checking. Same asSynchronizeableQuery.addSynchronizedQuerySpace(java.lang.String)
for all tables associated with the given entity.- Specified by:
addSynchronizedEntityName
in interfaceSynchronizeableQuery
- Parameters:
entityName
- The name of the entity upon whose defined query spaces we should additionally synchronize.- Returns:
this
, for method chaining- Throws:
MappingException
- Indicates the given name could not be resolved as an entity
-
addSynchronizedEntityClass
NativeQuery<T> addSynchronizedEntityClass(Class<?> entityClass) throws MappingException
Description copied from interface:SynchronizeableQuery
Adds an entity for (a) auto-flush checking and (b) query result cache invalidation checking. Same asSynchronizeableQuery.addSynchronizedQuerySpace(java.lang.String)
for all tables associated with the given entity.- Specified by:
addSynchronizedEntityClass
in interfaceSynchronizeableQuery
- Parameters:
entityClass
- The class of the entity upon whose defined query spaces we should additionally synchronize.- Returns:
this
, for method chaining- Throws:
MappingException
- Indicates the given class could not be resolved as an entity
-
setHibernateFlushMode
NativeQuery<T> setHibernateFlushMode(FlushMode flushMode)
Description copied from interface:CommonQueryContract
(Re)set the current FlushMode in effect for this query.- Specified by:
setHibernateFlushMode
in interfaceCommonQueryContract
- Specified by:
setHibernateFlushMode
in interfaceQuery<T>
- Parameters:
flushMode
- The new FlushMode to use.- Returns:
this
, for method chaining- See Also:
Session.getHibernateFlushMode()
,CommonQueryContract.getHibernateFlushMode()
-
setFlushMode
NativeQuery<T> setFlushMode(FlushModeType flushMode)
- Specified by:
setFlushMode
in interfaceQuery
- Specified by:
setFlushMode
in interfaceQuery<T>
- Specified by:
setFlushMode
in interfaceTypedQuery<T>
-
setCacheMode
NativeQuery<T> setCacheMode(CacheMode cacheMode)
Description copied from interface:CommonQueryContract
(Re)set the current CacheMode in effect for this query.- Specified by:
setCacheMode
in interfaceCommonQueryContract
- Specified by:
setCacheMode
in interfaceQuery<T>
- Parameters:
cacheMode
- The new CacheMode to use.- Returns:
this
, for method chaining- See Also:
CommonQueryContract.getCacheMode()
-
setCacheable
NativeQuery<T> setCacheable(boolean cacheable)
Description copied from interface:CommonQueryContract
Enable/disable second level query (result) caching for this query.- Specified by:
setCacheable
in interfaceCommonQueryContract
- Specified by:
setCacheable
in interfaceQuery<T>
- Parameters:
cacheable
- Should the query results be cacheable?- Returns:
this
, for method chaining- See Also:
CommonQueryContract.isCacheable()
-
setCacheRegion
NativeQuery<T> setCacheRegion(String cacheRegion)
Description copied from interface:CommonQueryContract
Set the name of the cache region where query results should be cached (if cached at all).- Specified by:
setCacheRegion
in interfaceCommonQueryContract
- Specified by:
setCacheRegion
in interfaceQuery<T>
- Parameters:
cacheRegion
- the name of a query cache region, ornull
to indicate that the default region should be used.- Returns:
this
, for method chaining- See Also:
CommonQueryContract.getCacheRegion()
-
setTimeout
NativeQuery<T> setTimeout(int timeout)
Description copied from interface:CommonQueryContract
Set the query timeout in seconds. NOTE it is important to understand that any value set here is eventually passed directly through to the JDBC Statement which expressly disallows negative values. So negative values should be avoided as a general rule.- Specified by:
setTimeout
in interfaceCommonQueryContract
- Specified by:
setTimeout
in interfaceQuery<T>
- Parameters:
timeout
- the timeout in seconds- Returns:
this
, for method chaining- See Also:
CommonQueryContract.getTimeout()
-
setFetchSize
NativeQuery<T> setFetchSize(int fetchSize)
Description copied from interface:CommonQueryContract
Sets a JDBC fetch size hint for the query.- Specified by:
setFetchSize
in interfaceCommonQueryContract
- Specified by:
setFetchSize
in interfaceQuery<T>
- Parameters:
fetchSize
- the fetch size hint- Returns:
this
, for method chaining- See Also:
CommonQueryContract.getFetchSize()
-
setReadOnly
NativeQuery<T> setReadOnly(boolean readOnly)
Description copied from interface:CommonQueryContract
Set the read-only/modifiable mode for entities and proxies loaded by this Query. This setting overrides the default setting for the persistence context.- Specified by:
setReadOnly
in interfaceCommonQueryContract
- Specified by:
setReadOnly
in interfaceQuery<T>
- Parameters:
readOnly
-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- Returns:
this
, for method chaining- See Also:
To set the default read-only/modifiable setting used for entities and proxies that are loaded into the session:
,PersistenceContext.setDefaultReadOnly(boolean)
,Read-only entities are not dirty-checked and snapshots of persistent state are not maintained. Read-only entities can be modified, but changes are not persisted. When a proxy is initialized, the loaded entity will have the same read-only/modifiable setting as the uninitialized proxy has, regardless of the session's current setting. The read-only/modifiable setting has no impact on entities/proxies returned by the query that existed in the session beforeQuery the query was executed.
-
setLockOptions
NativeQuery<T> setLockOptions(LockOptions lockOptions)
Description copied from interface:Query
Set the lock options for the query. Specifically only the following are taken into consideration: For alias-specific locking, useQuery.setLockMode(String, LockMode)
.- Specified by:
setLockOptions
in interfaceQuery<T>
- Parameters:
lockOptions
- The lock options to apply to the query.- Returns:
this
, for method chaining- See Also:
Query.getLockOptions()
-
setLockMode
NativeQuery<T> setLockMode(String alias, LockMode lockMode)
Description copied from interface:Query
Set the LockMode to use for specific alias (as defined in the query's FROM clause).The alias-specific lock modes specified here are added to the query's internal
LockOptions
.The effect of these alias-specific LockModes is somewhat dependent on the driver/database in use. Generally speaking, for maximum portability, this method should only be used to mark that the rows corresponding to the given alias should be included in pessimistic locking (
LockMode.PESSIMISTIC_WRITE
).- Specified by:
setLockMode
in interfaceQuery<T>
- Parameters:
alias
- a query alias, or"this"
for a collection filterlockMode
- The lock mode to apply.- Returns:
this
, for method chaining- See Also:
Query.getLockOptions()
-
setComment
NativeQuery<T> setComment(String comment)
Description copied from interface:Query
Set the comment for this query.- Specified by:
setComment
in interfaceQuery<T>
- Parameters:
comment
- The human-readable comment- Returns:
this
, for method chaining- See Also:
Query.getComment()
-
addQueryHint
NativeQuery<T> addQueryHint(String hint)
Description copied from interface:Query
Add a DB query hint to the SQL. These differ from JPA'sQueryHint
andQuery.getHints()
, which is specific to the JPA implementation and ignores DB vendor-specific hints. Instead, these are intended solely for the vendor-specific hints, such as Oracle's optimizers. Multiple query hints are supported; the Dialect will determine concatenation and placement.- Specified by:
addQueryHint
in interfaceQuery<T>
- Parameters:
hint
- The database specific query hint to add.
-
setMaxResults
NativeQuery<T> setMaxResults(int maxResult)
- Specified by:
setMaxResults
in interfaceQuery
- Specified by:
setMaxResults
in interfaceQuery<T>
- Specified by:
setMaxResults
in interfaceTypedQuery<T>
-
setFirstResult
NativeQuery<T> setFirstResult(int startPosition)
- Specified by:
setFirstResult
in interfaceQuery
- Specified by:
setFirstResult
in interfaceQuery<T>
- Specified by:
setFirstResult
in interfaceTypedQuery<T>
-
setHint
NativeQuery<T> setHint(String hintName, Object value)
-
setLockMode
NativeQuery<T> setLockMode(LockModeType lockMode)
- Specified by:
setLockMode
in interfaceQuery
- Specified by:
setLockMode
in interfaceQuery<T>
- Specified by:
setLockMode
in interfaceTypedQuery<T>
-
setTupleTransformer
NativeQuery<T> setTupleTransformer(TupleTransformer<T> transformer)
- Specified by:
setTupleTransformer
in interfaceQuery<T>
-
setResultListTransformer
NativeQuery<T> setResultListTransformer(ResultListTransformer transformer)
- Specified by:
setResultListTransformer
in interfaceQuery<T>
-
setResultTransformer
NativeQuery<T> setResultTransformer(ResultTransformer transformer)
- Specified by:
setResultTransformer
in interfaceQuery<T>
-
setParameter
NativeQuery<T> setParameter(String name, Object value)
Description copied from interface:Query
Bind a named query parameter using its inferred Type. If the parameter is defined in such a way that the Type cannot be inferred from its usage context then use of this form of binding is not allowed, andQuery.setParameter(String, Object, AllowableParameterType)
should be used instead- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceQuery<T>
- Specified by:
setParameter
in interfaceTypedQuery<T>
- Parameters:
name
- the parameter namevalue
- the (possibly-null) parameter value- Returns:
this
, for method chaining
-
setParameter
NativeQuery<T> setParameter(int position, Object value)
Description copied from interface:Query
Bind a positional query parameter using its inferred Type. If the parameter is defined in such a way that the Type cannot be inferred from its usage context then use of this form of binding is not allowed, andQuery.setParameter(int, Object, AllowableParameterType)
should be used instead- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceQuery<T>
- Specified by:
setParameter
in interfaceTypedQuery<T>
- Parameters:
position
- the position of the parameter in the query string, numbered from 0.value
- the possibly-null parameter value- Returns:
this
, for method chaining
-
setParameter
<P> NativeQuery<T> setParameter(QueryParameter<P> parameter, P val)
Description copied from interface:Query
Bind a query parameter using its inferred Type. If the parameter is defined in such a way that the Type cannot be inferred from its usage context then use of this form of binding is not allowed, andQuery.setParameter(QueryParameter, Object, AllowableParameterType)
should be used instead- Specified by:
setParameter
in interfaceQuery<T>
- Parameters:
parameter
- The query parameter mementoval
- the possibly-null parameter value- Returns:
this
, for method chaining
-
setParameter
NativeQuery<T> setParameter(Parameter<Instant> param, Instant value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceQuery<T>
-
setParameter
NativeQuery<T> setParameter(Parameter<LocalDateTime> param, LocalDateTime value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceQuery<T>
-
setParameter
NativeQuery<T> setParameter(Parameter<ZonedDateTime> param, ZonedDateTime value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceQuery<T>
-
setParameter
NativeQuery<T> setParameter(Parameter<OffsetDateTime> param, OffsetDateTime value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceQuery<T>
-
setParameter
NativeQuery<T> setParameter(String name, Instant value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceQuery<T>
-
setParameter
NativeQuery<T> setParameter(String name, LocalDateTime value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceQuery<T>
-
setParameter
NativeQuery<T> setParameter(String name, ZonedDateTime value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceQuery<T>
-
setParameter
NativeQuery<T> setParameter(String name, OffsetDateTime value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceQuery<T>
-
setParameter
NativeQuery<T> setParameter(int position, Instant value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceQuery<T>
-
setParameter
NativeQuery<T> setParameter(int position, LocalDateTime value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceQuery<T>
-
setParameter
NativeQuery<T> setParameter(int position, ZonedDateTime value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceQuery<T>
-
setParameter
NativeQuery<T> setParameter(int position, OffsetDateTime value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceQuery<T>
-
setParameter
<P> NativeQuery<T> setParameter(Parameter<P> param, P value)
- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceQuery<T>
- Specified by:
setParameter
in interfaceTypedQuery<T>
-
setParameter
NativeQuery<T> setParameter(String name, Object val, TemporalType temporalType)
Description copied from interface:Query
Bind a named query parameter as some form of date/time using the indicated temporal-type.- Specified by:
setParameter
in interfaceQuery<T>
- Parameters:
name
- the parameter nameval
- the possibly-null parameter valuetemporalType
- the temporal-type to use in binding the date/time- Returns:
this
, for method chaining
-
setParameter
NativeQuery<T> setParameter(int position, Object val, TemporalType temporalType)
Description copied from interface:Query
Bind a positional query parameter as some form of date/time using the indicated temporal-type.- Specified by:
setParameter
in interfaceQuery<T>
- Parameters:
position
- the position of the parameter in the query string, numbered from 0.val
- the possibly-null parameter valuetemporalType
- the temporal-type to use in binding the date/time- Returns:
this
, for method chaining
-
setParameter
<P> NativeQuery<T> setParameter(QueryParameter<P> parameter, P val, TemporalType temporalType)
Description copied from interface:Query
Bind a query parameter as some form of date/time using the indicated temporal-type.- Specified by:
setParameter
in interfaceQuery<T>
- Parameters:
parameter
- The query parameter mementoval
- the possibly-null parameter valuetemporalType
- the temporal-type to use in binding the date/time- Returns:
this
, for method chaining
-
setParameter
NativeQuery<T> setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceQuery<T>
- Specified by:
setParameter
in interfaceTypedQuery<T>
-
setParameter
NativeQuery<T> setParameter(Parameter<Date> param, Date value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceQuery<T>
- Specified by:
setParameter
in interfaceTypedQuery<T>
-
setParameter
NativeQuery<T> setParameter(String name, Calendar value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceQuery<T>
- Specified by:
setParameter
in interfaceTypedQuery<T>
-
setParameter
NativeQuery<T> setParameter(int position, Calendar value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceQuery<T>
- Specified by:
setParameter
in interfaceTypedQuery<T>
-
setParameter
NativeQuery<T> setParameter(String name, Date value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceQuery<T>
- Specified by:
setParameter
in interfaceTypedQuery<T>
-
setParameter
NativeQuery<T> setParameter(int position, Date value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceQuery<T>
- Specified by:
setParameter
in interfaceTypedQuery<T>
-
setParameterList
<P> NativeQuery<T> setParameterList(QueryParameter<P> parameter, Collection<P> values)
Description copied from interface:Query
Bind multiple values to a query parameter using its inferred Type. The Hibernate type of the parameter values is first detected via the usage/position in the query and if not sufficient secondly guessed from the class of the first object in the collection. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).- Specified by:
setParameterList
in interfaceQuery<T>
- Parameters:
parameter
- the parameter mementovalues
- a collection of values to list- Returns:
this
, for method chaining
-
setParameterList
NativeQuery<T> setParameterList(String name, Collection<?> values)
Description copied from interface:Query
Bind multiple values to a named query parameter. The Hibernate type of the parameter is first detected via the usage/position in the query and if not sufficient secondly guessed from the class of the first object in the collection. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).- Specified by:
setParameterList
in interfaceQuery<T>
- Parameters:
name
- the name of the parametervalues
- a collection of values to list- Returns:
this
, for method chaining
-
setParameterList
<P> NativeQuery<T> setParameterList(String name, Collection<? extends P> values, AllowableParameterType<P> type)
Description copied from interface:Query
Bind multiple values to a named query parameter. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).- Specified by:
setParameterList
in interfaceQuery<T>
- Parameters:
name
- the name of the parametervalues
- a collection of values to listtype
- the Hibernate allowable parameter type of the values- Returns:
this
, for method chaining
-
setParameterList
NativeQuery<T> setParameterList(String name, Object[] values, AllowableParameterType<?> type)
Description copied from interface:Query
Bind multiple values to a named query parameter. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).- Specified by:
setParameterList
in interfaceQuery<T>
- Parameters:
name
- the name of the parametervalues
- a collection of values to listtype
- the Hibernate type of the values- Returns:
this
, for method chaining
-
setParameterList
NativeQuery<T> setParameterList(String name, Object[] values)
Description copied from interface:Query
Bind multiple values to a named query parameter. The Hibernate type of the parameter is first detected via the usage/position in the query and if not sufficient secondly guessed from the class of the first object in the array. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).- Specified by:
setParameterList
in interfaceQuery<T>
- Parameters:
name
- the name of the parametervalues
- a collection of values to list- Returns:
this
, for method chaining
-
setParameter
<P> NativeQuery<T> setParameter(String name, P val, AllowableParameterType<P> type)
Description copied from interface:Query
Bind a named query parameter using the supplied Type- Specified by:
setParameter
in interfaceQuery<T>
- Parameters:
name
- the name of the parameterval
- the possibly-null parameter valuetype
- the Hibernate allowable parameter type- Returns:
this
, for method chaining
-
setParameter
<P> NativeQuery<T> setParameter(int position, P val, AllowableParameterType<P> type)
Description copied from interface:Query
Bind a value to a JDBC-style query parameter.- Specified by:
setParameter
in interfaceQuery<T>
- Parameters:
position
- the position of the parameter in the query string, numbered from 0.val
- the possibly-null parameter valuetype
- the Hibernate allowable parameter type- Returns:
this
, for method chaining
-
setParameter
<P> NativeQuery<T> setParameter(QueryParameter<P> parameter, P val, AllowableParameterType<P> type)
Description copied from interface:Query
Bind a query parameter using the supplied Type- Specified by:
setParameter
in interfaceQuery<T>
- Parameters:
parameter
- The query parameter mementoval
- the possibly-null parameter valuetype
- the Hibernate allowable parameter type- Returns:
this
, for method chaining
-
setParameter
<P> NativeQuery<T> setParameter(String name, P val, BasicTypeReference<P> type)
Description copied from interface:Query
Bind a named query parameter using the supplied Type- Specified by:
setParameter
in interfaceQuery<T>
- Parameters:
name
- the name of the parameterval
- the possibly-null parameter valuetype
- the Hibernate allowable parameter type- Returns:
this
, for method chaining
-
setParameter
<P> NativeQuery<T> setParameter(int position, P val, BasicTypeReference<P> type)
Description copied from interface:Query
Bind a value to a JDBC-style query parameter.- Specified by:
setParameter
in interfaceQuery<T>
- Parameters:
position
- the position of the parameter in the query string, numbered from 0.val
- the possibly-null parameter valuetype
- the Hibernate allowable parameter type- Returns:
this
, for method chaining
-
setParameter
<P> NativeQuery<T> setParameter(QueryParameter<P> parameter, P val, BasicTypeReference<P> type)
Description copied from interface:Query
Bind a query parameter using the supplied Type- Specified by:
setParameter
in interfaceQuery<T>
- Parameters:
parameter
- The query parameter mementoval
- the possibly-null parameter valuetype
- the Hibernate allowable parameter type- Returns:
this
, for method chaining
-
setParameterList
NativeQuery<T> setParameterList(int position, Collection<?> values)
Description copied from interface:Query
Bind multiple values to a positional query parameter. The Hibernate type of the parameter is first detected via the usage/position in the query and if not sufficient secondly guessed from the class of the first object in the collection. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).- Specified by:
setParameterList
in interfaceQuery<T>
- Parameters:
position
- the parameter positional labelvalues
- a collection of values to list- Returns:
this
, for method chaining
-
setParameterList
<P> NativeQuery<T> setParameterList(String name, Collection<? extends P> values, Class<P> type)
Description copied from interface:Query
Bind multiple values to a named query parameter. The Hibernate type of the parameter is first detected via the usage/position in the query and if not sufficient secondly guessed from the class of the first object in the collection. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).- Specified by:
setParameterList
in interfaceQuery<T>
- Parameters:
name
- the name of the parametervalues
- a collection of values to list- Returns:
this
, for method chaining
-
setParameterList
<P> NativeQuery<T> setParameterList(int position, Collection<? extends P> values, Class<P> type)
Description copied from interface:Query
Bind multiple values to a positional query parameter. The Hibernate type of the parameter is first detected via the usage/position in the query and if not sufficient secondly guessed from the class of the first object in the collection. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).- Specified by:
setParameterList
in interfaceQuery<T>
- Parameters:
position
- the parameter positional labelvalues
- a collection of values to list- Returns:
this
, for method chaining
-
setParameterList
<P> NativeQuery<T> setParameterList(int position, Collection<? extends P> values, AllowableParameterType<P> type)
Description copied from interface:Query
Bind multiple values to a positional query parameter. This is useful for binding a list of values to an expression such as foo.bar in (?1).- Specified by:
setParameterList
in interfaceQuery<T>
- Parameters:
position
- the parameter positional labelvalues
- a collection of values to listtype
- the Hibernate allowable parameter type of the values- Returns:
this
, for method chaining
-
setParameterList
NativeQuery<T> setParameterList(int position, Object[] values, AllowableParameterType<?> type)
Description copied from interface:Query
Bind multiple values to a named query parameter. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).- Specified by:
setParameterList
in interfaceQuery<T>
- Parameters:
position
- the parameter positional labelvalues
- a collection of values to listtype
- the Hibernate type of the values- Returns:
this
, for method chaining
-
setParameterList
NativeQuery<T> setParameterList(int position, Object[] values)
Description copied from interface:Query
Bind multiple values to a named query parameter. The Hibernate type of the parameter is first detected via the usage/position in the query and if not sufficient secondly guessed from the class of the first object in the array. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).- Specified by:
setParameterList
in interfaceQuery<T>
- Parameters:
position
- the parameter positional labelvalues
- a collection of values to list- Returns:
this
, for method chaining
-
setProperties
NativeQuery<T> setProperties(Object bean)
Description copied from interface:Query
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.- Specified by:
setProperties
in interfaceQuery<T>
- Parameters:
bean
- any JavaBean or POJO- Returns:
this
, for method chaining
-
setProperties
NativeQuery<T> setProperties(Map bean)
Description copied from interface:Query
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.- Specified by:
setProperties
in interfaceQuery<T>
- Parameters:
bean
- a java.util.Map- Returns:
this
, for method chaining
-
-