Interface Query<T>
- Type Parameters:
T- The result type for selection queries or the target type for mutation statements.
- All Superinterfaces:
CommonQueryContract, Query
- All Known Subinterfaces:
MutationOrSelectionQuery, 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.
The subtype NativeQuery represents a query written in the native SQL
dialect of the database.
This interface fills a very similar role to Query
in JPA, acting as a bridge to client code written for older versions of the
query APIs in JPA and Hibernate. Older versions did not carefully distinguish
selection queries from insert, update, and delete
mutation statements. Every instance of Query
may logically be classified as one or the other.
Direct use of this interface to execute a query or statement is now discouraged.
Instead, SelectionQuery should be used to execute a selection query,
and MutationQuery should be used to execute a mutation statement.
Therefore, operations of this interface which are only relevant to selection
queries, or only relevant to mutation statements, are now marked as deprecated.
- Selection queries are usually executed using
getResultList(),getSingleResult(), orgetSingleResultOrNull(), with the methodssetMaxResults(int)andsetFirstResult(int)controlling limits and pagination. All these methods are marked as deprecated, and should be called via an instance ofSelectionQuery. - Mutation statements are usually executed using
executeUpdate(), which is marked as deprecated, or usingMutationQuery.execute(). - The various overloads of
setParameter(String, Object)andsetParameter(int, Object)allow arguments to be bound to named and ordinal parameters defined by the query.
- See Also:
- API Note:
- Like
Queryin JPA 4, this interface is now essentially redundant. Newly written code should always preferSelectionQueryorMutationQuery.
-
Method Summary
Modifier and TypeMethodDescriptionaddQueryHint(String hint) Add a database query hint to the SQL query.disableFetchProfile(String profileName) Deprecated, for removal: This API element is subject to removal in a future version.enableFetchProfile(String profileName) Deprecated, for removal: This API element is subject to removal in a future version.intDeprecated, for removal: This API element is subject to removal in a future version.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.Use SelectionQuery instead as second-level cache interaction is only relevant for queries which return results.Deprecated.Use SelectionQuery instead as second-level cache interaction is only relevant for queries which return results.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 queriesintDeprecated.Use SelectionQuery instead as applying result limits is only relevant for queries which return results.default FlushModeTypeDeprecated.Deprecated.Use SelectionQuery instead as locking is only relevant for queries which return results.Deprecated.Use SelectionQuery instead as locking is only relevant for queries which return results.intDeprecated.Use SelectionQuery instead as applying result limits is only relevant for queries which return results.Deprecated, for removal: This API element is subject to removal in a future version.The variousQuery<T>subtypes already expose all relevant options; furthermore, this operation is a layer-breaker, exposing theQueryOptionsSPI type via an API.TheQuery<T>as a string, ornullin the case of a criteria query.Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead for queries which return results.Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead for queries which return results.Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead for queries which return results.Deprecated, for removal: This API element is subject to removal in a future version.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 query is cached.booleanDeprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as read-only mode is only relevant for selection querieslist()Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead for queries which return results.scroll()Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead for queries which return results.scroll(ScrollMode scrollMode) Deprecated, for removal: This API element is subject to removal in a future version.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) setEntityGraph(EntityGraph<? super T> graph, GraphSemantic semantic) Deprecated, for removal: This API element is subject to removal in a future version.Prefer passing the entity-graph while creating the query - SharedSessionContract.createSelectionQuery(String, EntityGraph)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.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 is only relevant for queries which return results.Set a hint.setLockMode(LockModeType lockMode) 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.setParameters(Object... arguments) 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 or disable query plan caching for this query, if available.setReadOnly(boolean readOnly) Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as read-only mode is only relevant for selection queriessetResultListTransformer(ResultListTransformer<T> transformer) Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as result list transformation is only relevant for queries which return results.setTimeout(int timeout) Specify a JDBC query timeout to use when executing the query.setTimeout(Timeout timeout) Specify a JDBC query timeout to use when executing the query.setTimeout(Integer timeout) Specify a JDBC query timeout to use when executing the query.<X> Query<X> setTupleTransformer(TupleTransformer<X> transformer) Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as tuple transformation is only relevant for queries which return results.stream()Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead for queries which return results.Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead for queries which return results.Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead for queries which return results.Methods inherited from interface CommonQueryContract
getComment, getEffectiveFlushMode, getParameterMetadata, getQueryFlushMode, getSession, getTimeoutMethods inherited from interface Query
getHints, getParameter, getParameter, getParameter, getParameter, getParameters, getParameterValue, getParameterValue, getParameterValue, isBound, unwrap
-
Method Details
-
getQueryString
-
setQueryFlushMode
Set theQueryFlushModeto use for this query.A
QueryFlushModeonly affects stateful sessions. A stateless session has no persistence context to flush.- Specified by:
setQueryFlushModein interfaceCommonQueryContract- Specified by:
setQueryFlushModein interfaceQuery- 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
Specify a JDBC query timeout to use when executing the query.- Specified by:
setTimeoutin interfaceCommonQueryContract- See Also:
- API Note:
- Since this is a legacy method of Hibernate, the timeout value is expressed in seconds.
-
setTimeout
Specify a JDBC query timeout to use when executing the query.- Specified by:
setTimeoutin interfaceCommonQueryContract- Specified by:
setTimeoutin interfaceQuery- See Also:
- API Note:
- Since this method is inherited from JPA, the timeout is expressed in milliseconds.
-
setTimeout
Specify a JDBC query timeout to use when executing the query.- Specified by:
setTimeoutin interfaceCommonQueryContract- Specified by:
setTimeoutin interfaceQuery
-
isQueryPlanCacheable
boolean isQueryPlanCacheable()Whether the execution plan for this query is cached.- Since:
- 6.3
-
setQueryPlanCacheable
-
setHint
Set a hint. Hints are a JPA-standard way to control provider-specific behavior affecting execution of the query. Clients of this 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.Since JPA 4,
TypedQuery.OptionandStatement.Optioncompete with query hints, offering a more type safe way to accommodate vendor extensions.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
@Nonnull <P> Query<T> setParameter(@Nonnull String parameter, @Nullable P argument, @Nonnull Class<P> type) 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
@Nonnull <P> Query<T> setParameter(@Nonnull String parameter, @Nullable P argument, @Nonnull Type<P> type) 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:
-
setParameters
- Specified by:
setParametersin interfaceCommonQueryContract- Specified by:
setParametersin 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
@Nonnull <P> Query<T> setParameter(@Nonnull QueryParameter<P> parameter, @Nullable P argument, @Nonnull Class<P> type) 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
@Nonnull <P> Query<T> setParameter(@Nonnull QueryParameter<P> parameter, @Nullable P argument, @Nonnull Type<P> type) 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
@Nonnull <P> Query<T> setConvertedParameter(@Nonnull String name, @Nullable P value, @Nonnull Class<? extends AttributeConverter<P, ?>> converter) - Specified by:
setConvertedParameterin interfaceCommonQueryContract- Specified by:
setConvertedParameterin interfaceQuery- See Also:
-
setConvertedParameter
@Nonnull <P> Query<T> setConvertedParameter(int position, @Nullable P value, @Nonnull 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
@Nonnull <P> Query<T> setParameterList(@Nonnull String parameter, @Nonnull Collection<? extends P> arguments, @Nonnull 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
@Nonnull <P> Query<T> setParameterList(@Nonnull String parameter, @Nonnull Collection<? extends P> arguments, @Nonnull Type<P> type) 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
@Nonnull <P> Query<T> setParameterList(@Nonnull String parameter, @Nonnull P[] arguments, @Nonnull Class<P> javaType) 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
-
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
@Nonnull <P> Query<T> setParameterList(int parameter, @Nonnull Collection<? extends P> arguments, @Nonnull Class<P> javaType) 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
@Nonnull <P> Query<T> setParameterList(int parameter, @Nonnull Collection<? extends P> arguments, @Nonnull Type<P> type) 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
@Nonnull <P> Query<T> setParameterList(int parameter, @Nonnull P[] arguments, @Nonnull Class<P> javaType) 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
@Nonnull <P> Query<T> setParameterList(int parameter, @Nonnull P[] arguments, @Nonnull Type<P> type) Bind multiple arguments to an ordinal query parameter using the givenType.- Specified by:
setParameterListin interfaceCommonQueryContract- Returns:
this, for method chaining
-
setParameterList
@Nonnull <P> Query<T> setParameterList(@Nonnull QueryParameter<P> parameter, @Nonnull Collection<? extends P> arguments) 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
@Nonnull <P> Query<T> setParameterList(@Nonnull QueryParameter<P> parameter, @Nonnull Collection<? extends P> arguments, @Nonnull 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
@Nonnull <P> Query<T> setParameterList(@Nonnull QueryParameter<P> parameter, @Nonnull Collection<? extends P> arguments, @Nonnull 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
@Nonnull <P> Query<T> setParameterList(@Nonnull QueryParameter<P> parameter, @Nonnull P[] arguments) 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
@Nonnull <P> Query<T> setParameterList(@Nonnull QueryParameter<P> parameter, @Nonnull P[] arguments, @Nonnull 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
@Nonnull <P> Query<T> setParameterList(@Nonnull QueryParameter<P> parameter, @Nonnull P[] arguments, @Nonnull Type<P> type) 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 queriesSpecify a JDBC fetch size to use when executing this query.- Parameters:
fetchSize- the fetch size hint- Returns:
this, for method chaining- See Also:
-
isReadOnly
Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as read-only mode is only relevant for selection queriesShould 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 is returned instead.The read-only/modifiable setting has no impact on entities/proxies returned by the query that existed in the session before the query was executed.
- 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
Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as read-only mode is only relevant for selection queriesSet 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(since="8.0", forRemoval=true) @Nonnull Query<T> setCacheMode(@Nonnull 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 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:
-
getCacheStoreMode
Deprecated.Use SelectionQuery instead as second-level cache interaction is only relevant for queries which return results.- Specified by:
getCacheStoreModein interfaceQuery
-
setCacheStoreMode
@Deprecated(since="8.0") @Nonnull Query<T> setCacheStoreMode(@Nonnull CacheStoreMode cacheStoreMode) Deprecated.Use SelectionQuery instead as second-level cache interaction is only relevant for queries which return results.- Specified by:
setCacheStoreModein interfaceQuery
-
getCacheRetrieveMode
Deprecated.Use SelectionQuery instead as second-level cache interaction is only relevant for queries which return results.- Specified by:
getCacheRetrieveModein interfaceQuery
-
setCacheRetrieveMode
@Deprecated(since="8.0") @Nonnull Query<T> setCacheRetrieveMode(@Nonnull CacheRetrieveMode cacheRetrieveMode) Deprecated.Use SelectionQuery instead as second-level cache interaction is only relevant for queries which return results.- Specified by:
setCacheRetrieveModein interfaceQuery
-
getMaxResults
Deprecated.Use SelectionQuery instead as applying result limits is only relevant for queries which return results.- Specified by:
getMaxResultsin interfaceQuery
-
setMaxResults
Deprecated.Use SelectionQuery instead as applying result limits is only relevant for queries which return results.- Specified by:
setMaxResultsin interfaceQuery
-
getFirstResult
Deprecated.Use SelectionQuery instead as applying result limits is only relevant for queries which return results.- Specified by:
getFirstResultin interfaceQuery
-
setFirstResult
Deprecated.Use SelectionQuery instead as applying result limits is only relevant for queries which return results.- Specified by:
setFirstResultin interfaceQuery
-
getLockMode
Deprecated.Use SelectionQuery instead as locking is only relevant for queries which return results.- Specified by:
getLockModein interfaceQuery
-
setLockMode
Deprecated.Use SelectionQuery instead as locking is only relevant for queries which return results.- Specified by:
setLockModein interfaceQuery
-
getHibernateLockMode
Deprecated.Use SelectionQuery instead as locking is 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 is only relevant for queries which return results.- See Also:
-
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- Since:
- 7.1
-
setTupleTransformer
@Deprecated(since="8.0", forRemoval=true) @Nonnull <X> Query<X> setTupleTransformer(@Nonnull TupleTransformer<X> transformer) Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as tuple transformation is only relevant for queries which return results.Set aTupleTransformer.- Since:
- 6.0
-
setResultListTransformer
@Deprecated(since="8.0", forRemoval=true) @Nonnull Query<T> setResultListTransformer(@Nonnull ResultListTransformer<T> transformer) Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead as result list transformation is only relevant for queries which return results.Set aResultListTransformer.- Since:
- 6.0
-
list
Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead for queries which return results.Execute theQuery<T>and return theQuery<T>results as aList. If theQuery<T>contains multiple items in the selection list, then by default each result in the list is packaged in an array of typeObject[].- Returns:
- the result list
-
getResultList
Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead for queries which return results.Execute theQuery<T>and return theQuery<T>results as aList. If theQuery<T>contains multiple items in the selection list, then by default each result in the list is packaged in an array of typeObject[].- Specified by:
getResultListin interfaceQuery- Returns:
- the results as a list
- Implementation Note:
- Delegates to
list()
-
scroll
Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead for queries which return results.Execute theQuery<T>and return the results in a scrollable form.This overload simply calls
scroll(ScrollMode)using the default scroll mode of the SQL dialect.- 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 databases.
-
scroll
@Deprecated(since="8.0", forRemoval=true) @Nonnull ScrollableResults<T> scroll(@Nonnull ScrollMode scrollMode) Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead for queries which return results.Execute theQuery<T>and return the results in a scrollable form. The capabilities of the returnedScrollableResultsdepend on the specifiedScrollMode.- API Note:
- Not every JDBC driver supports every
ScrollMode.
-
getResultStream
Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead for queries which return results.Execute theQuery<T>and return theQuery<T>results as aStream. If theQuery<T>contains multiple items in the selection list, then by default each result in the stream is packaged in an array of typeObject[].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, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead for queries which return results.Execute theQuery<T>and return theQuery<T>results as aStream. If theQuery<T>contains multiple items in the selection list, then by default each result in the stream is packaged in an array of typeObject[].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, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead for queries which return results.Execute theQuery<T>and return the single result of the query, ornullif theQuery<T>returns 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, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead for queries which return results.Execute theQuery<T>and return the single result of the query, throwing an exception if theQuery<T>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
-
getSingleResultOrNull
Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead for queries which return results.Execute theQuery<T>and return the single result of the query ornullif theQuery<T>returns no results, throwing and exception if theQuery<T>returns more than one result.- Specified by:
getSingleResultOrNullin interfaceQuery- Returns:
- the single result, if there is exactly one result,
or
nullif there are no results to return - Throws:
NonUniqueResultException- if there is more than one matching result
-
uniqueResultOptional
Deprecated, for removal: This API element is subject to removal in a future version.Use SelectionQuery instead for queries which return results.- Returns:
- the single result as an
Optional - Throws:
NonUniqueResultException- if there is more than one matching result
-
executeUpdate
Deprecated, for removal: This API element is subject to removal in a future version.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.
-
enableFetchProfile
@Deprecated(since="8.0", forRemoval=true) @Nonnull Query<T> enableFetchProfile(@Nonnull String profileName) Deprecated, for removal: This API element is subject to removal in a future version.Enable the fetch profile with the given name during execution of this query. If the requested fetch profile is already enabled, the call has no effect.This is an alternative way to specify the associations which should be fetched as part of the initial query.
- Parameters:
profileName- the name of the fetch profile to be enabled- Throws:
UnknownProfileException- Indicates that the given name does not match any known fetch profile names- See Also:
-
disableFetchProfile
@Deprecated(since="8.0", forRemoval=true) @Nonnull Query<T> disableFetchProfile(@Nonnull String profileName) Deprecated, for removal: This API element is subject to removal in a future version.Disable the fetch profile with the given name in this session. If the fetch profile is not currently enabled, the call has no effect.- Parameters:
profileName- the name of the fetch profile to be disabled- Throws:
UnknownProfileException- Indicates that the given name does not match any known fetch profile names- See Also:
-
getFlushMode
Deprecated.The JPAFlushModeTypein effect for this query. By default, theQuery<T>inherits theFlushModeof 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)
-
setEntityGraph
@Deprecated(since="8.0", forRemoval=true) @Nonnull Query<T> setEntityGraph(@Nonnull EntityGraph<? super T> graph, @Nonnull GraphSemantic semantic) Deprecated, for removal: This API element is subject to removal in a future version.Prefer passing the entity-graph while creating the query - SharedSessionContract.createSelectionQuery(String, EntityGraph)Apply anEntityGraphto the query.This is an alternative way to specify the associations which should be fetched as part of the initial query.
- Since:
- 6.3
- See Also:
-
getQueryOptions
Deprecated, for removal: This API element is subject to removal in a future version.The variousQuery<T>subtypes already expose all relevant options; furthermore, this operation is a layer-breaker, exposing theQueryOptionsSPI type via 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 a 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. -
setParameter
@Deprecated(since="7") @Nonnull Query<T> setParameter(@Nonnull Parameter<Calendar> parameter, @Nullable Calendar argument, @Nonnull TemporalType temporalType) Deprecated.Queryoverride- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- See Also:
-
setParameter
@Deprecated(since="7") @Nonnull Query<T> setParameter(@Nonnull Parameter<Date> parameter, @Nullable Date argument, @Nonnull TemporalType temporalType) Deprecated.Queryoverride- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- See Also:
-
setParameter
@Deprecated(since="7") @Nonnull Query<T> setParameter(@Nonnull String parameter, @Nullable Instant argument, @Nonnull TemporalType temporalType) Deprecated.Bind anInstantvalue to the namedQuery<T>parameter using just the portion indicated by the givenTemporalType.- Specified by:
setParameterin interfaceCommonQueryContract
-
setParameter
@Deprecated(since="7") @Nonnull Query<T> setParameter(@Nonnull String parameter, @Nullable Calendar argument, @Nonnull TemporalType temporalType) Deprecated.Queryoverride- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- See Also:
-
setParameter
@Deprecated(since="7") @Nonnull Query<T> setParameter(@Nonnull String parameter, @Nullable Date argument, @Nonnull TemporalType temporalType) Deprecated.Queryoverride- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- See Also:
-
setParameter
@Deprecated(since="7") @Nonnull Query<T> setParameter(int parameter, @Nullable Instant argument, @Nonnull TemporalType temporalType) Deprecated.Bind anInstantvalue to the ordinalQuery<T>parameter using just the portion indicated by the givenTemporalType.- Specified by:
setParameterin interfaceCommonQueryContract
-
setParameter
@Deprecated(since="7") @Nonnull Query<T> setParameter(int parameter, @Nullable Date argument, @Nonnull TemporalType temporalType) Deprecated.Queryoverride- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- See Also:
-
setParameter
@Deprecated(since="7") @Nonnull Query<T> setParameter(int parameter, @Nullable Calendar argument, @Nonnull TemporalType temporalType) Deprecated.Queryoverride- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- See Also:
-