Interface CommonQueryContract
- All Known Subinterfaces:
MutationQuery
,NativeQuery<T>
,NativeQueryImplementor<R>
,ProcedureCall
,ProcedureCallImplementor<R>
,Query<R>
,QueryImplementor<R>
,SelectionQuery<R>
,SqmQuery
,SqmQueryImplementor<R>
,SqmSelectionQuery<R>
,SqmSelectionQueryImplementor<R>
- All Known Implementing Classes:
AbstractCommonQueryContract
,AbstractQuery
,AbstractSelectionQuery
,DelegatingSqmSelectionQueryImplementor
- queries written in HQL or JPQL,
- queries written in the native SQL dialect of the database,
- criteria queries, and
- stored procedure calls.
Queries may have parameters, either ordinal or named, and the various
setParameter()
operations of this interface allow an argument to be
bound to a parameter. It's not usually necessary to explicitly specify the type
of an argument, but in rare cases where this is needed:
- an instance of an appropriate metamodel
Type
may be passed tosetParameter(int, Object, Type)
, or - the argument may be wrapped in a
TypedParameterValue
. (For JPA users, this second option avoids the need to cast theQuery
to a Hibernate-specific type.)
For example:
session.createSelectionQuery("from Person where address = :address", Person.class) .setParameter("address", address, Person_.address.getType()) .getResultList()
entityManager.createQuery( "from Person where address = :address", Person.class) .setParameter("address", TypedParameterValue.of(Person_.address.getType(), address)) .getResultList()
The operation setQueryFlushMode(QueryFlushMode)
allows a temporary flush
mode to be specified, which is in effect only during the execution of this query.
Setting the query flush mode does not affect the flush
mode of other operations performed via the parent session.
This operation is usually used as follows:
query.setQueryFlushMode(NO_FLUSH).getResultList()
The call to setQueryFlushMode(NO_FLUSH)
disables the usual automatic flush
operation that occurs before query execution.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionGet the comment that has been set for this query, if any.Deprecated.Deprecated.Get theParameterMetadata
object representing the parameters of this query, and providing access to theQueryParameter
s.TheQueryFlushMode
in effect for this query.Obtain the query timeout in seconds.setComment
(String comment) Set a comment for this query.setFlushMode
(FlushModeType flushMode) Deprecated.setHibernateFlushMode
(FlushMode flushMode) Deprecated.Set a hint.setParameter
(int parameter, Object value) Bind the given argument to an ordinal query parameter.setParameter
(int parameter, Instant value, TemporalType temporalType) Deprecated.sinceTemporalType
is deprecatedsetParameter
(int parameter, Calendar value, TemporalType temporalType) Deprecated.sinceTemporalType
is deprecatedsetParameter
(int parameter, Date value, TemporalType temporalType) Deprecated.sinceTemporalType
is deprecatedsetParameter
(int parameter, P value, Type<P> type) Bind the given argument to an ordinal query parameter using the givenType
.setParameter
(int parameter, P value, Class<P> type) setParameter
(Parameter<Calendar> param, Calendar value, TemporalType temporalType) Deprecated.sinceTemporalType
is deprecatedsetParameter
(Parameter<Date> param, Date value, TemporalType temporalType) Deprecated.sinceTemporalType
is deprecatedsetParameter
(Parameter<T> param, T value) setParameter
(String parameter, Object value) Bind the given argument to a named query parameter.setParameter
(String parameter, Instant value, TemporalType temporalType) Deprecated.sinceTemporalType
is deprecatedsetParameter
(String parameter, Calendar value, TemporalType temporalType) Deprecated.sinceTemporalType
is deprecatedsetParameter
(String parameter, Date value, TemporalType temporalType) Deprecated.sinceTemporalType
is deprecatedsetParameter
(String parameter, P value, Type<P> type) Bind the given argument to a named query parameter using the givenType
.setParameter
(String parameter, P value, Class<P> type) setParameter
(QueryParameter<P> parameter, P val, Type<P> type) Bind an argument to the query parameter represented by the givenQueryParameter
, using the givenType
.setParameter
(QueryParameter<P> parameter, P value, Class<P> type) Bind an argument to the query parameter represented by the givenQueryParameter
, using the givenClass
reference to attempt to infer theType
to use.setParameter
(QueryParameter<T> parameter, T value) Bind an argument to the query parameter represented by the givenQueryParameter
.setParameterList
(int parameter, Object[] values) Bind multiple arguments to an ordinal query parameter.setParameterList
(int parameter, Collection values) Bind multiple arguments to an ordinal query parameter.setParameterList
(int parameter, Collection<? extends P> values, Type<P> type) Bind multiple arguments to an ordinal query parameter using the givenType
.setParameterList
(int parameter, Collection<? extends P> values, Class<P> javaType) setParameterList
(int parameter, P[] values, Type<P> type) Bind multiple arguments to an ordinal query parameter using the givenType
.setParameterList
(int parameter, P[] values, Class<P> javaType) setParameterList
(String parameter, Object[] values) Bind multiple arguments to a named query parameter.setParameterList
(String parameter, Collection values) Bind multiple arguments to a named query parameter.setParameterList
(String parameter, Collection<? extends P> values, Type<P> type) Bind multiple arguments to a named query parameter using the givenType
.setParameterList
(String parameter, Collection<? extends P> values, Class<P> javaType) Bind multiple arguments to a named query parameter using the givenClass
reference to attempt to infer theType
If unable to infer an appropriateType
, fall back tosetParameterList(String, Collection)
.setParameterList
(String parameter, P[] values, Type<P> type) Bind multiple arguments to a named query parameter using the givenType
.setParameterList
(String parameter, P[] values, Class<P> javaType) Bind multiple arguments to a named query parameter using the given Class reference to attempt to determine theType
to use.setParameterList
(QueryParameter<P> parameter, Collection<? extends P> values) Bind multiple arguments to the query parameter represented by the givenQueryParameter
.setParameterList
(QueryParameter<P> parameter, Collection<? extends P> values, Type<P> type) Bind multiple arguments to the query parameter represented by the givenQueryParameter
, using the givenType
.setParameterList
(QueryParameter<P> parameter, Collection<? extends P> values, Class<P> javaType) Bind multiple arguments to the query parameter represented by the givenQueryParameter
using the givenClass
reference to attempt to infer theType
to use.setParameterList
(QueryParameter<P> parameter, P[] values) Bind multiple arguments to the query parameter represented by the givenQueryParameter
.setParameterList
(QueryParameter<P> parameter, P[] values, Type<P> type) Bind multiple arguments to the query parameter represented by the givenQueryParameter
, using the given theType
.setParameterList
(QueryParameter<P> parameter, P[] values, Class<P> javaType) Bind multiple arguments to the query parameter represented by the givenQueryParameter
using the givenClass
reference to attempt to infer theType
to 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 givenMap
to named parameters of the query, matching key names with parameter names and mapping value types to Hibernate types using heuristics.setQueryFlushMode
(QueryFlushMode queryFlushMode) Set theQueryFlushMode
to use for this query.setTimeout
(int timeout) Set the query timeout in seconds.setTimeout
(Timeout timeout) Apply a timeout to the corresponding database query.
-
Method Details
-
getQueryFlushMode
QueryFlushMode getQueryFlushMode()TheQueryFlushMode
in effect for this query.By default, this is
QueryFlushMode.DEFAULT
, and theFlushMode
of the owningSession
determines whether it is flushed.- Since:
- 7.0
- See Also:
-
setQueryFlushMode
Set theQueryFlushMode
to use for this query.- Since:
- 7.0
- See Also:
-
getFlushMode
Deprecated.The JPAFlushModeType
in effect for this query. By default, the query inherits theFlushMode
of theSession
from which it originates. -
setFlushMode
Deprecated.Set theFlushMode
to use for this query.Setting this to
null
ultimately indicates to use theFlushMode
of the session. UsesetHibernateFlushMode(org.hibernate.FlushMode)
passingFlushMode.MANUAL
instead to indicate that no automatic flushing should occur. -
getHibernateFlushMode
Deprecated. -
setHibernateFlushMode
Deprecated.Set the currentFlushMode
in effect for this query.- See Also:
- Implementation Note:
- Setting to
null
ultimately indicates to use theFlushMode
of the session. UseFlushMode.MANUAL
instead to indicate that no automatic flushing should occur.
-
getTimeout
Integer getTimeout()Obtain the query timeout in seconds.This value is eventually passed along to the JDBC statement via
Statement.setQueryTimeout(int)
.A value of zero indicates no timeout.
-
setTimeout
Set the query timeout in seconds.Any value set here is eventually passed directly along to the JDBC statement, which expressly disallows negative values. So negative values should be avoided as a general rule, although certain "magic values" are handled - see Timeouts.NO_WAIT.
A value of zero indicates no timeout.
- Parameters:
timeout
- the timeout in seconds- Returns:
this
, for method chaining- See Also:
-
setTimeout
Apply a timeout to the corresponding database query.- Parameters:
timeout
- The timeout to apply- Returns:
this
, for method chaining
-
getComment
String getComment()Get the comment that has been set for this query, if any. -
setComment
Set a comment for this query.- See Also:
-
setHint
Set a hint. The hints understood by Hibernate are enumerated byAvailableHints
.- See Also:
- API Note:
- Hints are a
JPA-standard way to control provider-specific behavior
affecting execution of the query. Clients of the native API
defined by Hibernate should make use of type-safe operations
of this interface and of its subtypes. For example,
SelectionQuery.setCacheRegion(java.lang.String)
is preferred overHibernateHints.HINT_CACHE_REGION
.
-
getParameterMetadata
ParameterMetadata getParameterMetadata()Get theParameterMetadata
object representing the parameters of this query, and providing access to theQueryParameter
s.- Since:
- 7.0
-
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
. -
setParameter
Bind the given argument to a named query parameter using the givenClass
reference to attempt to infer theType
. If unable to infer an appropriateType
, fall back tosetParameter(String, Object)
.- See Also:
-
setParameter
Bind the given argument to a named query parameter using the givenType
. -
setParameter
@Deprecated(since="7") CommonQueryContract setParameter(String parameter, Instant value, TemporalType temporalType) Deprecated.sinceTemporalType
is deprecatedBind anInstant
to the named query parameter using just the portion indicated by the givenTemporalType
. -
setParameter
@Deprecated(since="7") CommonQueryContract setParameter(String parameter, Calendar value, TemporalType temporalType) Deprecated.sinceTemporalType
is deprecated -
setParameter
@Deprecated(since="7") CommonQueryContract setParameter(String parameter, Date value, TemporalType temporalType) Deprecated.sinceTemporalType
is deprecated -
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
. -
setParameter
Bind the given argument to an ordinal query parameter using the givenClass
reference to attempt to infer theType
. If unable to infer an appropriateType
, fall back tosetParameter(int, Object)
.- See Also:
-
setParameter
Bind the given argument to an ordinal query parameter using the givenType
. -
setParameter
@Deprecated(since="7") CommonQueryContract setParameter(int parameter, Instant value, TemporalType temporalType) Deprecated.sinceTemporalType
is deprecatedBind anInstant
to an ordinal query parameter using just the portion indicated by the givenTemporalType
. -
setParameter
@Deprecated(since="7") CommonQueryContract setParameter(int parameter, Date value, TemporalType temporalType) Deprecated.sinceTemporalType
is deprecated -
setParameter
@Deprecated(since="7") CommonQueryContract setParameter(int parameter, Calendar value, TemporalType temporalType) Deprecated.sinceTemporalType
is deprecated -
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".
- Parameters:
parameter
- the query parameter mementovalue
- 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 givenClass
reference to attempt to infer theType
to use. If unable to infer an appropriateType
, fall back tosetParameter(QueryParameter, Object)
.- Parameters:
parameter
- the query parameter mementovalue
- the argument, which might be nulltype
- aType
representing 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
.- Parameters:
parameter
- the query parameter mementoval
- the argument, which might be nulltype
- aType
representing the type of the parameter- Returns:
this
, for method chaining
-
setParameter
- See Also:
-
setParameter
@Deprecated(since="7") CommonQueryContract setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType) Deprecated.sinceTemporalType
is deprecated -
setParameter
@Deprecated(since="7") CommonQueryContract setParameter(Parameter<Date> param, Date value, TemporalType temporalType) Deprecated.sinceTemporalType
is deprecated -
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.
- Returns:
this
, for method chaining- See Also:
- API Note:
- This is used for binding a list of values to an expression
such as
entity.field in (:values)
.
-
setParameterList
<P> CommonQueryContract setParameterList(String parameter, Collection<? extends P> values, Class<P> javaType) Bind multiple arguments to a named query parameter using the givenClass
reference to attempt to infer theType
If unable to infer an appropriateType
, fall back tosetParameterList(String, Collection)
.- Returns:
this
, for method chaining- See Also:
- API Note:
- This is used for binding a list of values to an expression
such as
entity.field in (:values)
.
-
setParameterList
<P> CommonQueryContract setParameterList(String parameter, Collection<? extends P> values, Type<P> type) Bind multiple arguments to a named query parameter using the givenType
.- Returns:
this
, for method chaining- API Note:
- This is used for binding a list of values to an expression
such as
entity.field in (:values)
.
-
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
- Returns:
this
, for method chaining- API Note:
- This is used for binding a list of values to an expression
such as
entity.field in (:values)
.
-
setParameterList
Bind multiple arguments to a named query parameter using the given Class reference to attempt to determine theType
to use. If unable to determine an appropriateType
,setParameterList(String, Collection)
is used- Returns:
this
, for method chaining- See Also:
- API Note:
- This is used for binding a list of values to an expression
such as
entity.field in (:values)
.
-
setParameterList
Bind multiple arguments to a named query parameter using the givenType
.- Returns:
this
, for method chaining- API Note:
- This is used for binding a list of values to an expression
such as
entity.field in (:values)
.
-
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
- Returns:
this
, for method chaining- API Note:
- This is used for binding a list of values to an expression
such as
entity.field in (:values)
.
-
setParameterList
<P> CommonQueryContract setParameterList(int parameter, Collection<? extends P> values, Class<P> javaType) Bind multiple arguments to an ordinal query parameter using the givenClass
reference to attempt to infer theType
. If unable to infer an appropriateType
, fall back tosetParameterList(String, Collection)
.- Returns:
this
, for method chaining- See Also:
- API Note:
- This is used for binding a list of values to an expression
such as
entity.field in (:values)
.
-
setParameterList
<P> CommonQueryContract setParameterList(int parameter, Collection<? extends P> values, Type<P> type) Bind multiple arguments to an ordinal query parameter using the givenType
.- Returns:
this
, for method chaining- API Note:
- This is used for binding a list of values to an expression
such as
entity.field in (:values)
.
-
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
- Returns:
this
, for method chaining- API Note:
- This is used for binding a list of values to an expression
such as
entity.field in (:values)
.
-
setParameterList
Bind multiple arguments to an ordinal query parameter using the givenClass
reference to attempt to infer theType
. If unable to infer an appropriateType
, fall back tosetParameterList(String, Collection)
.- Returns:
this
, for method chaining- See Also:
- API Note:
- This is used for binding a list of values to an expression
such as
entity.field in (:values)
.
-
setParameterList
Bind multiple arguments to an ordinal query parameter using the givenType
.- Returns:
this
, for method chaining- API Note:
- This is used for binding a list of values to an expression
such as
entity.field in (:values)
.
-
setParameterList
<P> CommonQueryContract setParameterList(QueryParameter<P> parameter, Collection<? extends P> values) 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.
- Parameters:
parameter
- the parameter mementovalues
- a collection of arguments- Returns:
this
, for method chaining
-
setParameterList
<P> CommonQueryContract setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, Class<P> javaType) Bind multiple arguments to the query parameter represented by the givenQueryParameter
using the givenClass
reference to attempt to infer theType
to use. If unable to infer an appropriateType
, fall back to usingsetParameterList(String, Collection)
.- Returns:
this
, for method chaining- See Also:
- API Note:
- This is used for binding a list of values to an expression
such as
entity.field in (:values)
.
-
setParameterList
<P> CommonQueryContract setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, Type<P> type) Bind multiple arguments to the query parameter represented by the givenQueryParameter
, using the givenType
.- Returns:
this
, for method chaining- API Note:
- This is used for binding a list of values to an expression
such as
entity.field in (:values)
.
-
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
QueryParameter
and the type of the first given argument.- Parameters:
parameter
- the parameter mementovalues
- a collection of arguments- Returns:
this
, for method chaining
-
setParameterList
<P> CommonQueryContract setParameterList(QueryParameter<P> parameter, P[] values, Class<P> javaType) Bind multiple arguments to the query parameter represented by the givenQueryParameter
using the givenClass
reference to attempt to infer theType
to use. If unable to infer an appropriateType
, fall back to usingsetParameterList(String, Collection)
.- Returns:
this
, for method chaining- See Also:
- API Note:
- This is used for binding a list of values to an expression
such as
entity.field in (:values)
.
-
setParameterList
Bind multiple arguments to the query parameter represented by the givenQueryParameter
, using the given theType
.- Returns:
this
, for method chaining- API Note:
- This is used for binding a list of values to an expression
such as
entity.field in (:values)
.
-
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.- Parameters:
bean
- any JavaBean or POJO- Returns:
this
, for method chaining
-
setProperties
Bind the values of the givenMap
to named parameters of the query, matching key names with parameter names and mapping value types to Hibernate types using heuristics.- Parameters:
bean
- aMap
of names to arguments- Returns:
this
, for method chaining
-
getQueryFlushMode()