Interface Query<T>
- Type Parameters:
T- The result type for selection queries or the target type for mutation queries.
- All Superinterfaces:
CommonQueryContract, Query
- All Known Subinterfaces:
MutationQueryImplementor<T>, NativeQuery<T>, NativeQueryImplementor<R>, ProcedureCallImplementor<R>, QueryImplementor<T>, SelectionQuery<R>, SelectionQueryImplementor<R>
- a Query
written in HQL or native SQL, - a named Query
written in HQL or native SQL, or - a criteria query.
- a named Query
The subtype
This type simply mixes the
A
A
Note that this interface offers no real advantages over NativeQuery represents a QueryTypedQuery interface defined by JPA with
SelectionQuery and MutationQuery. Unfortunately, JPA does
not distinguish between selection queries and
mutation queries, so we lose that distinction here.
However, every Query may logically be classified as one or the other.
Query may be obtained from the Session by
calling:
SharedSessionContract.createQuery(String, Class), passing the HQL as a
string,
SharedSessionContract.createQuery(jakarta.persistence.criteria.CriteriaQuery),
passing a criteria
object, or
SharedSessionContract.createNamedQuery(String, Class) passing the name
of a QueryNamedQuery or
NamedNativeQuery.
Query controls how a Query
getResultList() or
getSingleResult().
setMaxResults(int) and setFirstResult(int)
control limits and pagination.
setParameter(String, Object) and
setParameter(int, Object) allow arguments to be bound to named
and ordinal parameters defined by the query.
SelectionQuery
except for compatibility with the JPA-defined TypedQuery interface.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionaddQueryHint(String hint) Add a database query hint to the SQL query.Casts this query as aSelectionQuery.Covariant override of Query.asStatement().intDeprecated.Use MutationQuery instead for queries which mutate data.Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as caching is only relevant for selection queriesDeprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as caching is only relevant for selection queriesDeprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as fetch size is only relevant for selection queriesdefault FlushModeTypeDeprecated.Deprecated.Use SelectionQuery instead as locking are only relevant for queries which return results.Deprecated.Use SelectionQuery instead as locking is only relevant for queries which return results.Deprecated, for removal: This API element is subject to removal in a future version.The various Querysubtypes already expose all relevant options; plus exposing QueryOptions is layer-breaking as it is an SPI contract exposed on an API. The Queryas a string, or nullin the case of a criteria query.Deprecated.Use SelectionQuery instead for queries which return results.Deprecated.Use SelectionQuery instead for queries which return results.Deprecated.Use SelectionQuery instead for queries which return results.booleanDeprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as caching is only relevant for selection queriesbooleanWhether the execution plan for this Queryis cached. booleanShould entities and proxies loaded by this Query be put in read-only mode? If the read-only/modifiable setting was not initialized, then the default read-only/modifiable setting for the persistence context i s returned instead.list()Deprecated.Use SelectionQuery instead for queries which return results.<R> SelectionQuery<R> Covariant override of Query.ofType(Class).scroll()Deprecated.Use SelectionQuery instead for queries which return results.scroll(ScrollMode scrollMode) Deprecated.Use SelectionQuery instead for queries which return results.setCacheable(boolean cacheable) Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as caching is only relevant for selection queriessetCacheMode(CacheMode cacheMode) Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as caching is only relevant for selection queriessetCacheRegion(String cacheRegion) Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as caching is only relevant for selection queriessetCacheRetrieveMode(CacheRetrieveMode cacheRetrieveMode) Deprecated.Use SelectionQuery instead as second-level cache interaction is only relevant for queries which return results.setCacheStoreMode(CacheStoreMode cacheStoreMode) Deprecated.Use SelectionQuery instead as second-level cache interaction is only relevant for queries which return results.setComment(String comment) Set the comment for this query.setConvertedParameter(int position, P value, Class<? extends AttributeConverter<P, ?>> converter) setConvertedParameter(String name, P value, Class<? extends AttributeConverter<P, ?>> converter) setFetchSize(int fetchSize) Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as fetch size is only relevant for selection queriessetFirstResult(int startPosition) Deprecated.Use SelectionQuery instead as applying result limits is only relevant for queries which return results.setFlushMode(FlushModeType flushMode) Deprecated.Use setQueryFlushMode(QueryFlushMode) instead.setFollowOnLockingStrategy(Locking.FollowOn strategy) Deprecated.Use SelectionQuery instead as locking is only relevant for queries which return results.setFollowOnStrategy(Locking.FollowOn strategy) Deprecated.Use SelectionQuery instead as locking is only relevant for queries which return results.setHibernateLockMode(LockMode lockMode) Deprecated.Use SelectionQuery instead as locking are only relevant for queries which return results.Set a hint.setLockMode(LockModeType lockMode) Deprecated.Use SelectionQuery instead as locking are only relevant for queries which return results.setLockScope(PessimisticLockScope lockScope) Deprecated.Use SelectionQuery instead as locking is only relevant for queries which return results.setLockTimeout(Timeout lockTimeout) Deprecated.Use SelectionQuery instead as locking is only relevant for queries which return results.setMaxResults(int maxResults) Deprecated.Use SelectionQuery instead as applying result limits is only relevant for queries which return results.setParameter(int parameter, Object argument) Bind the given argument to an ordinal query parameter.setParameter(int parameter, Instant argument, TemporalType temporalType) Deprecated.setParameter(int parameter, Calendar argument, TemporalType temporalType) Deprecated.setParameter(int parameter, Date argument, TemporalType temporalType) Deprecated.setParameter(int parameter, P argument, Type<P> type) Bind the given argument to an ordinal query parameter using the givenType.setParameter(int parameter, P argument, Class<P> type) setParameter(Parameter<Calendar> parameter, Calendar argument, TemporalType temporalType) Deprecated.setParameter(Parameter<Date> parameter, Date argument, TemporalType temporalType) Deprecated.setParameter(Parameter<P> parameter, P argument) setParameter(String parameter, Object argument) Bind the given argument to a named query parameter.setParameter(String parameter, Instant argument, TemporalType temporalType) Deprecated.setParameter(String parameter, Calendar argument, TemporalType temporalType) Deprecated.setParameter(String parameter, Date argument, TemporalType temporalType) Deprecated.setParameter(String parameter, P argument, Type<P> type) Bind the given argument to a named query parameter using the givenType.setParameter(String parameter, P argument, Class<P> type) setParameter(QueryParameter<P> parameter, P argument) Bind an argument to the query parameter represented by the givenQueryParameter.setParameter(QueryParameter<P> parameter, P argument, Type<P> type) Bind an argument to the query parameter represented by the givenQueryParameter, using the givenType.setParameter(QueryParameter<P> parameter, P argument, Class<P> type) Bind an argument to the query parameter represented by the givenQueryParameter, using the givenClassreference to attempt to infer theTypeto use.setParameterList(int parameter, Object[] arguments) Bind multiple arguments to an ordinal query parameter.setParameterList(int parameter, Collection arguments) Bind multiple arguments to an ordinal query parameter.setParameterList(int parameter, Collection<? extends P> arguments, Type<P> type) Bind multiple arguments to an ordinal query parameter using the givenType.setParameterList(int parameter, Collection<? extends P> arguments, Class<P> javaType) setParameterList(int parameter, P[] arguments, Type<P> type) Bind multiple arguments to an ordinal query parameter using the givenType.setParameterList(int parameter, P[] arguments, Class<P> javaType) setParameterList(String parameter, Object[] values) Bind multiple arguments to a named query parameter.setParameterList(String parameter, Collection arguments) Bind multiple arguments to a named query parameter.setParameterList(String parameter, Collection<? extends P> arguments, Type<P> type) Bind multiple arguments to a named query parameter using the givenType.setParameterList(String parameter, Collection<? extends P> arguments, Class<P> javaType) Bind multiple arguments to a named query parameter using the givenClassreference to attempt to infer theTypeIf unable to infer an appropriateType, fall back toCommonQueryContract.setParameterList(String, Collection).setParameterList(String parameter, P[] arguments, Type<P> type) Bind multiple arguments to a named query parameter using the givenType.setParameterList(String parameter, P[] arguments, Class<P> javaType) Bind multiple arguments to a named query parameter using the given Class reference to attempt to determine theTypeto use.setParameterList(QueryParameter<P> parameter, Collection<? extends P> arguments) Bind multiple arguments to the query parameter represented by the givenQueryParameter.setParameterList(QueryParameter<P> parameter, Collection<? extends P> arguments, Type<P> type) Bind multiple arguments to the query parameter represented by the givenQueryParameter, using the givenType.setParameterList(QueryParameter<P> parameter, Collection<? extends P> arguments, Class<P> javaType) Bind multiple arguments to the query parameter represented by the givenQueryParameterusing the givenClassreference to attempt to infer theTypeto use.setParameterList(QueryParameter<P> parameter, P[] arguments) Bind multiple arguments to the query parameter represented by the givenQueryParameter.setParameterList(QueryParameter<P> parameter, P[] arguments, Type<P> type) Bind multiple arguments to the query parameter represented by the givenQueryParameter, using the given theType.setParameterList(QueryParameter<P> parameter, P[] arguments, Class<P> javaType) Bind multiple arguments to the query parameter represented by the givenQueryParameterusing the givenClassreference to attempt to infer theTypeto use.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.setProperties(Map bean) Bind the values of the givenMapto named parameters of the query, matching key names with parameter names and mapping value types to Hibernate types using heuristics.setQueryFlushMode(QueryFlushMode queryFlushMode) Set theQueryFlushModeto use for this query.setQueryPlanCacheable(boolean queryPlanCacheable) Enable/disable Queryplan caching for this query, if available. setReadOnly(boolean readOnly) Set the read-only/modifiable mode for entities and proxies loaded by thisQuery.setResultListTransformer(ResultListTransformer<T> transformer) Set aResultListTransformer.setTimeout(int timeout) Apply a timeout to the corresponding database query.setTimeout(Timeout timeout) Apply a timeout to the corresponding database query.setTimeout(Integer timeout) Apply a timeout to the corresponding database query.<X> Query<X> setTupleTransformer(TupleTransformer<X> transformer) Set aTupleTransformer.stream()Deprecated.Use SelectionQuery instead for queries which return results.Deprecated.Use SelectionQuery instead for queries which return results.Deprecated.Use SelectionQuery instead for queries which return results.<R> SelectionQuery<R> withEntityGraph(EntityGraph<R> entityGraph) Covariant override of Query.withEntityGraph(EntityGraph).Methods inherited from interface CommonQueryContract
asMutationQuery, asSelectionQuery, asSelectionQuery, asSelectionQuery, getComment, getEffectiveFlushMode, getParameterMetadata, getQueryFlushMode, getSession, getTimeoutMethods inherited from interface Query
getCacheRetrieveMode, getCacheStoreMode, getFirstResult, getHints, getLockMode, getMaxResults, getParameter, getParameter, getParameter, getParameter, getParameters, getParameterValue, getParameterValue, getParameterValue, getSingleResultOrNull, isBound, unwrap
-
Method Details
-
getQueryString
String getQueryString()The Queryas a string, or nullin the case of a criteria query. -
asSelectionQuery
SelectionQuery<T> asSelectionQuery()Description copied from interface:CommonQueryContractCasts this query as aSelectionQuery.- Specified by:
asSelectionQueryin interfaceCommonQueryContract
-
ofType
Covariant override of Query.ofType(Class).- Specified by:
ofTypein interfaceQuery- See Also:
- API Note:
- Jakarta Persistence declares that the generic IllegalStateException exception be thrown, as opposed to something more meaningful like Hibernate's IllegalSelectQueryException.
-
withEntityGraph
Covariant override of Query.withEntityGraph(EntityGraph).- Specified by:
withEntityGraphin interfaceQuery- See Also:
- API Note:
- Jakarta Persistence declares that the generic IllegalStateException exception be thrown, as opposed to something more meaningful like Hibernate's IllegalSelectQueryException.
-
asStatement
MutationQuery asStatement()Covariant override of Query.asStatement().- Specified by:
asStatementin interfaceQuery- See Also:
- API Note:
- Jakarta Persistence declares that the generic IllegalStateException exception be thrown, as opposed to something more meaningful like Hibernate's IllegalMutationQueryException.
-
setQueryFlushMode
Description copied from interface:CommonQueryContractSet theQueryFlushModeto use for this query.- Specified by:
setQueryFlushModein interfaceCommonQueryContract- See Also:
-
setComment
Set the comment for this query.If SQL commenting is enabled, the comment will be added to the SQL query sent to the database, which may be useful for identifying the source of troublesome queries.
SQL commenting may be enabled using the configuration property "hibernate.use_sql_comments".
- Specified by:
setCommentin interfaceCommonQueryContract- See Also:
-
addQueryHint
Add a database query hint to the SQL query.Multiple query hints may be specified. The operation
Dialect.getQueryHintString(String, List)determines how the hint is actually added to the SQL query.- Specified by:
addQueryHintin interfaceCommonQueryContract
-
setTimeout
Apply a timeout to the corresponding database query.- Specified by:
setTimeoutin interfaceCommonQueryContract- See Also:
-
setTimeout
Apply a timeout to the corresponding database query.- Specified by:
setTimeoutin interfaceCommonQueryContract- Specified by:
setTimeoutin interfaceQuery- See Also:
-
setTimeout
Apply a timeout to the corresponding database query.- Specified by:
setTimeoutin interfaceCommonQueryContract- Specified by:
setTimeoutin interfaceQuery
-
isQueryPlanCacheable
boolean isQueryPlanCacheable()Whether the execution plan for this Queryis cached. -
setQueryPlanCacheable
-
setHint
Set a hint. Hints are a JPA-standard way to control provider-specific behavior affecting execution of the query. Clients of native Hibernate API should make use of type-safe operations of this interface and of its subtypes. For example,SelectionQuery.setCacheRegion(String)is preferred overHibernateHints.HINT_CACHE_REGION.The hints understood by Hibernate are enumerated by
AvailableHints.- Specified by:
setHintin interfaceCommonQueryContract- Specified by:
setHintin interfaceQuery- See Also:
-
setParameter
Bind the given argument to a named query parameter.If the type of the parameter cannot be inferred from the context in which it occurs, use one of the overloads which accepts a "type", or pass a
TypedParameterValue.- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- See Also:
-
setParameter
Bind the given argument to a named query parameter using the givenClassreference to attempt to infer theType. If unable to infer an appropriateType, fall back toCommonQueryContract.setParameter(String, Object).- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- See Also:
-
setParameter
Bind the given argument to a named query parameter using the givenType.- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery
-
setParameter
Bind the given argument to an ordinal query parameter.If the type of the parameter cannot be inferred from the context in which it occurs, use one of the overloads which accepts a "type", or pass a
TypedParameterValue.- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- See Also:
-
setParameter
Bind the given argument to an ordinal query parameter using the givenClassreference to attempt to infer theType. If unable to infer an appropriateType, fall back toCommonQueryContract.setParameter(int, Object).- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- See Also:
-
setParameter
Bind the given argument to an ordinal query parameter using the givenType.- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery
-
setParameter
Bind an argument to the query parameter represented by the givenQueryParameter.If the type of the parameter cannot be inferred from the context in which it occurs, use one of the overloads which accepts a "type".
- Specified by:
setParameterin interfaceCommonQueryContract- Parameters:
parameter- the query parameter mementoargument- the argument, which might be null- Returns:
this, for method chaining- See Also:
-
setParameter
Bind an argument to the query parameter represented by the givenQueryParameter, using the givenClassreference to attempt to infer theTypeto use. If unable to infer an appropriateType, fall back toCommonQueryContract.setParameter(QueryParameter, Object).- Specified by:
setParameterin interfaceCommonQueryContract- Parameters:
parameter- the query parameter mementoargument- the argument, which might be nulltype- aTyperepresenting the type of the parameter- Returns:
this, for method chaining- See Also:
-
setParameter
Bind an argument to the query parameter represented by the givenQueryParameter, using the givenType.- Specified by:
setParameterin interfaceCommonQueryContract- Parameters:
parameter- the query parameter mementoargument- the argument, which might be nulltype- aTyperepresenting the type of the parameter- Returns:
this, for method chaining
-
setParameter
- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- See Also:
-
setConvertedParameter
<P> Query<T> setConvertedParameter(String name, P value, Class<? extends AttributeConverter<P, ?>> converter) - Specified by:
setConvertedParameterin interfaceCommonQueryContract- Specified by:
setConvertedParameterin interfaceQuery- See Also:
-
setConvertedParameter
<P> Query<T> setConvertedParameter(int position, P value, Class<? extends AttributeConverter<P, ?>> converter) - Specified by:
setConvertedParameterin interfaceCommonQueryContract- Specified by:
setConvertedParameterin interfaceQuery- See Also:
-
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.- Specified by:
setPropertiesin interfaceCommonQueryContract- Parameters:
bean- any JavaBean or POJO- Returns:
this, for method chaining
-
setProperties
Bind the values of the givenMapto named parameters of the query, matching key names with parameter names and mapping value types to Hibernate types using heuristics.- Specified by:
setPropertiesin interfaceCommonQueryContract- Parameters:
bean- aMapof names to arguments- Returns:
this, for method chaining
-
setParameterList
Bind multiple arguments to a named query parameter.The "type mapping" for the binding is inferred from the type of the first collection element.
- Specified by:
setParameterListin interfaceCommonQueryContract- Returns:
this, for method chaining- See Also:
-
setParameterList
<P> Query<T> setParameterList(String parameter, Collection<? extends P> arguments, Class<P> javaType) Bind multiple arguments to a named query parameter using the givenClassreference to attempt to infer theTypeIf unable to infer an appropriateType, fall back toCommonQueryContract.setParameterList(String, Collection).- Specified by:
setParameterListin interfaceCommonQueryContract- Returns:
this, for method chaining- See Also:
-
setParameterList
Bind multiple arguments to a named query parameter using the givenType.- Specified by:
setParameterListin interfaceCommonQueryContract- Returns:
this, for method chaining
-
setParameterList
Bind multiple arguments to a named query parameter.The "type mapping" for the binding is inferred from the type of the first collection element
- Specified by:
setParameterListin interfaceCommonQueryContract- Returns:
this, for method chaining
-
setParameterList
Bind multiple arguments to a named query parameter using the given Class reference to attempt to determine theTypeto use. If unable to determine an appropriateType,CommonQueryContract.setParameterList(String, Collection)is used- Specified by:
setParameterListin interfaceCommonQueryContract- Returns:
this, for method chaining- See Also:
-
setParameterList
Bind multiple arguments to a named query parameter using the givenType.- Specified by:
setParameterListin interfaceCommonQueryContract- Returns:
this, for method chaining
-
setParameterList
Bind multiple arguments to an ordinal query parameter.The "type mapping" for the binding is inferred from the type of the first collection element
- Specified by:
setParameterListin interfaceCommonQueryContract- Returns:
this, for method chaining
-
setParameterList
Bind multiple arguments to an ordinal query parameter using the givenClassreference to attempt to infer theType. If unable to infer an appropriateType, fall back toCommonQueryContract.setParameterList(String, Collection).- Specified by:
setParameterListin interfaceCommonQueryContract- Returns:
this, for method chaining- See Also:
-
setParameterList
Bind multiple arguments to an ordinal query parameter using the givenType.- Specified by:
setParameterListin interfaceCommonQueryContract- Returns:
this, for method chaining
-
setParameterList
Bind multiple arguments to an ordinal query parameter.The "type mapping" for the binding is inferred from the type of the first collection element
- Specified by:
setParameterListin interfaceCommonQueryContract- Returns:
this, for method chaining
-
setParameterList
Bind multiple arguments to an ordinal query parameter using the givenClassreference to attempt to infer theType. If unable to infer an appropriateType, fall back toCommonQueryContract.setParameterList(String, Collection).- Specified by:
setParameterListin interfaceCommonQueryContract- Returns:
this, for method chaining- See Also:
-
setParameterList
Bind multiple arguments to an ordinal query parameter using the givenType.- Specified by:
setParameterListin interfaceCommonQueryContract- Returns:
this, for method chaining
-
setParameterList
Bind multiple arguments to the query parameter represented by the givenQueryParameter.The type of the parameter is inferred from the context in which it occurs, and from the type of the first given argument.
- Specified by:
setParameterListin interfaceCommonQueryContract- Parameters:
parameter- the parameter mementoarguments- a collection of arguments- Returns:
this, for method chaining
-
setParameterList
<P> Query<T> setParameterList(QueryParameter<P> parameter, Collection<? extends P> arguments, Class<P> javaType) Bind multiple arguments to the query parameter represented by the givenQueryParameterusing the givenClassreference to attempt to infer theTypeto use. If unable to infer an appropriateType, fall back to usingCommonQueryContract.setParameterList(String, Collection).- Specified by:
setParameterListin interfaceCommonQueryContract- Returns:
this, for method chaining- See Also:
-
setParameterList
<P> Query<T> setParameterList(QueryParameter<P> parameter, Collection<? extends P> arguments, Type<P> type) Bind multiple arguments to the query parameter represented by the givenQueryParameter, using the givenType.- Specified by:
setParameterListin interfaceCommonQueryContract- Returns:
this, for method chaining
-
setParameterList
Bind multiple arguments to the query parameter represented by the givenQueryParameter.The type of the parameter is inferred between the context in which it occurs, the type associated with the
QueryParameterand the type of the first given argument.- Specified by:
setParameterListin interfaceCommonQueryContract- Parameters:
parameter- the parameter mementoarguments- a collection of arguments- Returns:
this, for method chaining
-
setParameterList
Bind multiple arguments to the query parameter represented by the givenQueryParameterusing the givenClassreference to attempt to infer theTypeto use. If unable to infer an appropriateType, fall back to usingCommonQueryContract.setParameterList(String, Collection).- Specified by:
setParameterListin interfaceCommonQueryContract- Returns:
this, for method chaining- See Also:
-
setParameterList
Bind multiple arguments to the query parameter represented by the givenQueryParameter, using the given theType.- Specified by:
setParameterListin interfaceCommonQueryContract- Returns:
this, for method chaining
-
getFetchSize
Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as fetch size is only relevant for selection queriesObtain the JDBC fetch size hint in effect for this query. This value is eventually passed along to the JDBC query viaStatement.setFetchSize(int). As defined by JDBC, this value is a hint to the driver to indicate how many rows to fetch from the database when more rows are needed.- Returns:
- The timeout in seconds
- See Also:
- Implementation Note:
- JDBC expressly defines this value as a hint. Depending on the driver, it may or may not have any
effect on the actual query execution and
ResultSetprocessing .
-
setFetchSize
Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as fetch size is only relevant for selection queriesSets a JDBC fetch size hint for the query.- Parameters:
fetchSize- the fetch size hint- Returns:
this, for method chaining- See Also:
-
isReadOnly
boolean isReadOnly()Should entities and proxies loaded by this Query be put in read-only mode? If the read-only/modifiable setting was not initialized, then the default read-only/modifiable setting for the persistence context i s returned instead.- Returns:
trueif the entities and proxies loaded by the query will be put in read-only mode;falseotherwise (they will be modifiable)- See Also:
-
setReadOnly
Set the read-only/modifiable mode for entities and proxies loaded by thisQuery. This setting overrides the default setting for the persistence context,Session.isDefaultReadOnly().To set the default read-only/modifiable setting used for entities and proxies that are loaded into the session, use
Session.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.
- Parameters:
readOnly-trueindicates that entities and proxies loaded by the query are to be put in read-only mode;falseindicates that entities and proxies loaded by the query will be put in modifiable mode- Returns:
this, for method chaining
-
isCacheable
Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as caching is only relevant for selection queriesShould the results of the query be stored in the second level cache?This is different to second level caching of any returned entities and collections, which is controlled by
getCacheMode().The query being "eligible" for caching does not necessarily mean its results will be cached. Second-level query caching still has to be enabled on the
SessionFactoryfor this to happen. Usually that is controlled by the configuration setting "hibernate.cache.use_query_cache". -
setCacheable
Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as caching is only relevant for selection queriesEnable/disable second level query (result) caching for this query.- See Also:
-
getCacheMode
Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as caching is only relevant for selection queriesObtain theCacheModein effect for this query. By default, the query inherits theCacheModeof the session from which it originates.The
CacheModehere affects the use of entity and collection caches as the query result set is processed. For caching of the actual query results, useisCacheable()andgetCacheRegion().In order for this setting to have any affect, second-level caching must be enabled and the entities and collections must be eligible for storage in the second-level cache.
- See Also:
-
setCacheMode
Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as caching is only relevant for selection queriesSet the currentCacheModein effect for this query.Set it to
nullto indicate that theCacheModeof thesessionshould be used.- See Also:
-
getCacheRegion
Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as caching is only relevant for selection queriesObtain the name of the second level query cache region in which query results will be stored (if they are cached, see the discussion onisCacheable()for more information).nullindicates that the default region should be used. -
setCacheRegion
Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as caching is only relevant for selection queriesSet the name of the cache region where query results should be cached (assumingisCacheable()).nullindicates to use the default region.- See Also:
-
setCacheStoreMode
Deprecated.Use SelectionQuery instead as second-level cache interaction is only relevant for queries which return results.- Specified by:
setCacheStoreModein interfaceQuery
-
setCacheRetrieveMode
Deprecated.Use SelectionQuery instead as second-level cache interaction is only relevant for queries which return results.- Specified by:
setCacheRetrieveModein interfaceQuery
-
setMaxResults
Deprecated.Use SelectionQuery instead as applying result limits is only relevant for queries which return results.- Specified by:
setMaxResultsin interfaceQuery
-
setFirstResult
Deprecated.Use SelectionQuery instead as applying result limits is only relevant for queries which return results.- Specified by:
setFirstResultin interfaceQuery
-
setLockMode
Deprecated.Use SelectionQuery instead as locking are only relevant for queries which return results.- Specified by:
setLockModein interfaceQuery
-
getHibernateLockMode
Deprecated.Use SelectionQuery instead as locking are only relevant for queries which return results.Get the rootLockModefor the query, expressed using Hibernate's native LockMode instead of JPA's LockModeType.- See Also:
-
setHibernateLockMode
Deprecated.Use SelectionQuery instead as locking are only relevant for queries which return results.- See Also:
-
getLockTimeout
Deprecated.Use SelectionQuery instead as locking is only relevant for queries which return results.Timeout applied specifically to pessimistic lock acquisition. -
setLockTimeout
Deprecated.Use SelectionQuery instead as locking is only relevant for queries which return results.Set a timeout to be applied specifically to pessimistic lock acquisition.- See Also:
-
setLockScope
Deprecated.Use SelectionQuery instead as locking is only relevant for queries which return results.Apply a scope to any pessimistic locking applied to the query.- Parameters:
lockScope- The lock scope to apply- Returns:
this, for method chaining
-
setFollowOnLockingStrategy
Deprecated.Use SelectionQuery instead as locking is only relevant for queries which return results.Control how Hibernate should handle cases where it is determined subsequent SQL queries would be needs to completely accomplish locking as requested.- Parameters:
strategy- The strategy for follow-on locking.- Returns:
this, for method chaining
-
setFollowOnStrategy
Deprecated.Use SelectionQuery instead as locking is only relevant for queries which return results.Control how Hibernate should handle cases where it is determined subsequent SQL queries would be needs to completely accomplish locking as requested.- Parameters:
strategy- The strategy for follow-on locking.- Returns:
this, for method chaining
-
setTupleTransformer
Set aTupleTransformer. -
setResultListTransformer
Set aResultListTransformer. -
list
Deprecated.Use SelectionQuery instead for queries which return results.Execute the Queryand return the Query results as a List. If the Querycontains multiple items in the selection list, then by default each result in the list is packaged in an array of type Object[].- Returns:
- the result list
-
getResultList
Deprecated.Use SelectionQuery instead for queries which return results.Execute the Queryand return the Query results as a List. If the Querycontains multiple items in the selection list, then by default each result in the list is packaged in an array of type Object[].- Specified by:
getResultListin interfaceQuery- Returns:
- the results as a list
- Implementation Note:
- Delegates to
list()
-
scroll
Deprecated.Use SelectionQuery instead for queries which return results.Execute the Queryand return the results in a scrollable form. This overload simply calls
scroll(ScrollMode)using the dialect default scroll mode.- API Note:
- The exact behavior of this method depends somewhat
on the level of JDBC driver support for scrollable
ResultSets, and so is not very portable between database.
-
scroll
Deprecated.Use SelectionQuery instead for queries which return results.Execute the Queryand return the results in a scrollable form. The capabilities of the returned ScrollableResultsdepend on the specifiedScrollMode.- API Note:
- The exact behavior of this method depends somewhat
on the level of JDBC driver support for scrollable
ResultSets, and so is not very portable between database.
-
getResultStream
Deprecated.Use SelectionQuery instead for queries which return results.Execute the Queryand return the Query results as a Stream. If the Querycontains multiple items in the selection list, then by default each result in the stream is packaged in an array of type Object[].The client should call
BaseStream.close()after processing the stream so that resources are freed as soon as possible.- Specified by:
getResultStreamin interfaceQuery- Returns:
- The results as a
Stream - Implementation Note:
- Delegates to
stream(), which in turn delegates to this method. Implementors should implement at least one of these methods.
-
stream
Deprecated.Use SelectionQuery instead for queries which return results.Execute the Queryand return the Query results as a Stream. If the Querycontains multiple items in the selection list, then by default each result in the stream is packaged in an array of type Object[].The client should call
BaseStream.close()after processing the stream so that resources are freed as soon as possible.- Returns:
- The results as a
Stream - Since:
- 5.2
-
uniqueResult
Deprecated.Use SelectionQuery instead for queries which return results.Execute the Queryand return the single result of the query, or nullif the Queryreturns no results. - Returns:
- the single result or
nullif there is no result to return - Throws:
NonUniqueResultException- if there is more than one matching result
-
getSingleResult
Deprecated.Use SelectionQuery instead for queries which return results.Execute the Queryand return the single result of the query, throwing an exception if the Query returns no results. - Specified by:
getSingleResultin interfaceQuery- Returns:
- the single result, only if there is exactly one
- Throws:
NonUniqueResultException- if there is more than one matching resultNoResultException- if there is no result to return
-
uniqueResultOptional
Deprecated.Use SelectionQuery instead for queries which return results.Execute the Queryand return the single result of the Query as an instance of Optional.- Returns:
- the single result as an
Optional - Throws:
NonUniqueResultException- if there is more than one matching result
-
executeUpdate
Deprecated.Use MutationQuery instead for queries which mutate data.Execute an insert, update, or delete statement, and return the number of affected entities.For use with instances of
MutationQuerycreated usingSharedSessionContract.createMutationQuery(String),SharedSessionContract.createNamedMutationQuery(String),SharedSessionContract.createNativeMutationQuery(String), orSharedSessionContract.createMutationQuery(jakarta.persistence.criteria.CriteriaStatement).- Specified by:
executeUpdatein interfaceQuery- Returns:
- the number of affected entity instances (may differ from the number of affected rows)
- See Also:
- API Note:
- This method is needed because this interface extends
Query, which defines this method. SeeMutationQueryandSelectionQuery.
-
getFlushMode
Deprecated.The JPAFlushModeTypein effect for this query. By default, the Queryinherits the FlushModeof theSessionfrom which it originates.- Specified by:
getFlushModein interfaceQuery- See Also:
- API Note:
- Inherited from Jakarta Persistence. Prefer CommonQueryContract.getQueryFlushMode()
-
setFlushMode
Deprecated.Use setQueryFlushMode(QueryFlushMode) instead.Set theFlushModeTypeto use for this query.Setting this to
nullultimately indicates to use theFlushModeof the session. UsesetQueryFlushMode(QueryFlushMode)passingQueryFlushMode.NO_FLUSHinstead to indicate that no automatic flushing should occur.- Specified by:
setFlushModein interfaceQuery- See Also:
- API Note:
- Inherited from Jakarta Persistence. Prefer setQueryFlushMode(QueryFlushMode)
-
getQueryOptions
Deprecated, for removal: This API element is subject to removal in a future version.The various Querysubtypes already expose all relevant options; plus exposing QueryOptions is layer-breaking as it is an SPI contract exposed on an API. Get the execution options for thisQuery. Many of the setters of this object update the state of the returnedQueryOptions. This is useful because it gives access to s primitive value in its (nullable) wrapper form, rather than the primitive form as required by JPA. This allows us to distinguish whether a value has been explicitly set by the client.- Returns:
- Return the encapsulation of this query's options.
-
setParameter
@Deprecated(since="7") Query<T> setParameter(Parameter<Calendar> parameter, Calendar argument, TemporalType temporalType) Deprecated.Queryoverride- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- See Also:
-
setParameter
@Deprecated(since="7") Query<T> setParameter(Parameter<Date> parameter, Date argument, TemporalType temporalType) Deprecated.Queryoverride- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- See Also:
-
setParameter
@Deprecated(since="7") Query<T> setParameter(String parameter, Instant argument, TemporalType temporalType) Deprecated.Bind anInstantvalue to the named Queryparameter using just the portion indicated by the given TemporalType.- Specified by:
setParameterin interfaceCommonQueryContract
-
setParameter
@Deprecated(since="7") Query<T> setParameter(String parameter, Calendar argument, TemporalType temporalType) Deprecated.Queryoverride- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- See Also:
-
setParameter
@Deprecated(since="7") Query<T> setParameter(String parameter, Date argument, TemporalType temporalType) Deprecated.Queryoverride- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- See Also:
-
setParameter
@Deprecated(since="7") Query<T> setParameter(int parameter, Instant argument, TemporalType temporalType) Deprecated.Bind anInstantvalue to the ordinal Queryparameter using just the portion indicated by the given TemporalType.- Specified by:
setParameterin interfaceCommonQueryContract
-
setParameter
@Deprecated(since="7") Query<T> setParameter(int parameter, Date argument, TemporalType temporalType) Deprecated.Queryoverride- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- See Also:
-
setParameter
@Deprecated(since="7") Query<T> setParameter(int parameter, Calendar argument, TemporalType temporalType) Deprecated.Queryoverride- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- See Also:
-