Top Description Methods
org.hibernate.query

public Interface CommonQueryContract

Known Direct Subinterfaces
org.hibernate.query.MutationQuery, org.hibernate.query.SelectionQuery, org.hibernate.query.spi.SqmQuery, org.hibernate.procedure.ProcedureCall
Known Direct Implementers
org.hibernate.query.spi.AbstractCommonQueryContract
Imports
java.time.Instant, java.util.Calendar, .Collection, .Date, .Map, org.hibernate.FlushMode, .Session, jakarta.persistence.FlushModeType, .Parameter, .TemporalType

Defines the aspects of query execution and parameter binding that apply to all forms of querying: HQL/JPQL queries, native SQL queries, 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, TypedParameterValue may be used.

The operation setFlushMode(FlushModeType) allows a temporary flush mode to be specified, which is in effect only during the execution of this query. Setting the flush mode at the query level does not affect the flush mode of other operations performed via the parent session. This operation is usually used as follows:

query.setFlushMode(COMMIT).getResultList()

The call to setFlushMode(COMMIT) disables the usual automatic flush operation that occurs before query execution.

Authors
Steve Ebersole, Gavin King
See Also
jakarta.persistence.Query, SelectionQuery, MutationQuery

Method Summary

Modifier and TypeMethod and Description
public String
getComment()

Get the comment that has been set for this query, if any.

public FlushModeType
getFlushMode()

The JPA FlushModeType in effect for this query.

public FlushMode
getHibernateFlushMode()

The FlushMode in effect for this query.

public Integer
getTimeout()

Obtain the query timeout in seconds.

public CommonQueryContract
setComment(String comment)

Set a comment for this query.

public CommonQueryContract
setFlushMode(FlushModeType flushMode)

Set the FlushMode in to use for this query.

public CommonQueryContract
setHibernateFlushMode(FlushMode flushMode)

Set the current FlushMode in effect for this query.

public CommonQueryContract
setHint(String hintName, Object value)

Set a hint.

public CommonQueryContract
setParameter(String parameter, Object value)

Bind the given argument to a named query parameter.

public <P> CommonQueryContract
setParameter(String parameter, P value, Class<P> type)

Bind the given argument to a named query parameter using the given Class reference to attempt to infer the BindableType.

public <P> CommonQueryContract
setParameter(String parameter, P value, BindableType<P> type)

Bind the given argument to a named query parameter using the given BindableType.

public CommonQueryContract
setParameter(String parameter, Instant value, TemporalType temporalType)

Bind an Instant to the named query parameter using just the portion indicated by the given TemporalType.

public CommonQueryContract
setParameter(String parameter, Calendar value, TemporalType temporalType)

public CommonQueryContract
setParameter(String parameter, Date value, TemporalType temporalType)

public CommonQueryContract
setParameter(int parameter, Object value)

Bind the given argument to an ordinal query parameter.

public <P> CommonQueryContract
setParameter(int parameter, P value, Class<P> type)

Bind the given argument to an ordinal query parameter using the given Class reference to attempt to infer the BindableType.

public <P> CommonQueryContract
setParameter(int parameter, P value, BindableType<P> type)

Bind the given argument to an ordinal query parameter using the given BindableType.

public CommonQueryContract
setParameter(int parameter, Instant value, TemporalType temporalType)

Bind an Instant to an ordinal query parameter using just the portion indicated by the given TemporalType.

public CommonQueryContract
setParameter(int parameter, Date value, TemporalType temporalType)

public CommonQueryContract
setParameter(int parameter, Calendar value, TemporalType temporalType)

public <T> CommonQueryContract

Returns:

this, for method chaining
setParameter
(QueryParameter<T>
the query parameter memento
parameter
,
T
the argument, which might be null
value
)

Bind an argument to the query parameter represented by the given QueryParameter.

public <P> CommonQueryContract

Returns:

this, for method chaining
setParameter
(QueryParameter<P>
the query parameter memento
parameter
,
P
the argument, which might be null
value
,
Class<P>
a BindableType representing the type of the parameter
type
)

Bind an argument to the query parameter represented by the given QueryParameter, using the given Class reference to attempt to infer the BindableType to use.

public <P> CommonQueryContract

Returns:

this, for method chaining
setParameter
(QueryParameter<P>
the query parameter memento
parameter
,
P
the argument, which might be null
val
,
BindableType<P>
a BindableType representing the type of the parameter
type
)

Bind an argument to the query parameter represented by the given QueryParameter, using the given BindableType.

public <T> CommonQueryContract
setParameter(Parameter<T> param, T value)

public CommonQueryContract
setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType)

public CommonQueryContract
setParameter(Parameter<Date> param, Date value, TemporalType temporalType)

public CommonQueryContract

Returns:

this, for method chaining
setParameterList
(String parameter, Collection<E> values)

Bind multiple arguments to a named query parameter.

public <P> CommonQueryContract

Returns:

this, for method chaining
setParameterList
(String parameter, Collection<? extends P> values, Class<P> javaType)

Bind multiple arguments to a named query parameter using the given Class reference to attempt to infer the BindableType If unable to infer an appropriate BindableType, fall back to setParameterList(String, Collection).

public <P> CommonQueryContract

Returns:

this, for method chaining
setParameterList
(String parameter, Collection<? extends P> values, BindableType<P> type)

Bind multiple arguments to a named query parameter using the given BindableType.

public CommonQueryContract

Returns:

this, for method chaining
setParameterList
(String parameter, Object[] values)

Bind multiple arguments to a named query parameter.

public <P> CommonQueryContract

Returns:

this, for method chaining
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 the BindableType to use.

public <P> CommonQueryContract

Returns:

this, for method chaining
setParameterList
(String parameter, P[] values, BindableType<P> type)

Bind multiple arguments to a named query parameter using the given BindableType.

public CommonQueryContract

Returns:

this, for method chaining
setParameterList
(int parameter, Collection<E> values)

Bind multiple arguments to an ordinal query parameter.

public <P> CommonQueryContract

Returns:

this, for method chaining
setParameterList
(int parameter, Collection<? extends P> values, Class<P> javaType)

Bind multiple arguments to an ordinal query parameter using the given Class reference to attempt to infer the BindableType.

public <P> CommonQueryContract

Returns:

this, for method chaining
setParameterList
(int parameter, Collection<? extends P> values, BindableType<P> type)

Bind multiple arguments to an ordinal query parameter using the given BindableType.

public CommonQueryContract

Returns:

this, for method chaining
setParameterList
(int parameter, Object[] values)

Bind multiple arguments to an ordinal query parameter.

public <P> CommonQueryContract

Returns:

this, for method chaining
setParameterList
(int parameter, P[] values, Class<P> javaType)

Bind multiple arguments to an ordinal query parameter using the given Class reference to attempt to infer the BindableType.

public <P> CommonQueryContract

Returns:

this, for method chaining
setParameterList
(int parameter, P[] values, BindableType<P> type)

Bind multiple arguments to an ordinal query parameter using the given BindableType.

public <P> CommonQueryContract

Returns:

this, for method chaining
setParameterList
(QueryParameter<P>
the parameter memento
parameter
,
Collection<? extends P>
a collection of arguments
values
)

Bind multiple arguments to the query parameter represented by the given QueryParameter.

public <P> CommonQueryContract

Returns:

this, for method chaining
setParameterList
(QueryParameter<P> parameter, Collection<? extends P> values, Class<P> javaType)

Bind multiple arguments to the query parameter represented by the given QueryParameter using the given Class reference to attempt to infer the BindableType to use.

public <P> CommonQueryContract

Returns:

this, for method chaining
setParameterList
(QueryParameter<P> parameter, Collection<? extends P> values, BindableType<P> type)

Bind multiple arguments to the query parameter represented by the given QueryParameter, using the given BindableType.

public <P> CommonQueryContract

Returns:

this, for method chaining
setParameterList
(QueryParameter<P>
the parameter memento
parameter
,
P[]
a collection of arguments
values
)

Bind multiple arguments to the query parameter represented by the given QueryParameter.

public <P> CommonQueryContract

Returns:

this, for method chaining
setParameterList
(QueryParameter<P> parameter, P[] values, Class<P> javaType)

Bind multiple arguments to the query parameter represented by the given QueryParameter using the given Class reference to attempt to infer the BindableType to use.

public <P> CommonQueryContract

Returns:

this, for method chaining
setParameterList
(QueryParameter<P> parameter, P[] values, BindableType<P> type)

Bind multiple arguments to the query parameter represented by the given QueryParameter, using the given the BindableType.

public CommonQueryContract

Returns:

this, for method chaining
setProperties
(Object
any JavaBean or POJO
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.

public CommonQueryContract

Returns:

this, for method chaining
setProperties
(Map<K, V>
a Map of names to arguments
bean
)

Bind the values of the given Map to named parameters of the query, matching key names with parameter names and mapping value types to Hibernate types using heuristics.

public CommonQueryContract

Returns:

this, for method chaining
setTimeout
(int
the timeout in seconds
timeout
)

Set the query timeout in seconds.

Method Detail

getCommentback to summary
public String getComment()

Get the comment that has been set for this query, if any.

getFlushModeback to summary
public FlushModeType getFlushMode()

The JPA FlushModeType in effect for this query. By default, the query inherits the FlushMode of the Session from which it originates.

See Also
getHibernateFlushMode, Session#getHibernateFlushMode
getHibernateFlushModeback to summary
public FlushMode getHibernateFlushMode()

The FlushMode in effect for this query. By default, the query inherits the FlushMode of the Session from which it originates.

See Also
Session#getHibernateFlushMode
getTimeoutback to summary
public Integer getTimeout()

Obtain the query timeout in seconds.

This value is eventually passed along to the JDBC statement via java.sql.Statement#setQueryTimeout(int).

A value of zero indicates no timeout.

See Also
java.sql.Statement#getQueryTimeout(), java.sql.Statement#setQueryTimeout(int)
setCommentback to summary
public CommonQueryContract setComment(String comment)

Set a comment for this query.

See Also
Query#setComment(String)
setFlushModeback to summary
public CommonQueryContract setFlushMode(FlushModeType flushMode)

Set the FlushMode in to use for this query.

Implementation Note

Setting to null ultimately indicates to use the FlushMode of the Session. Use setHibernateFlushMode passing FlushMode#MANUAL instead to indicate that no automatic flushing should occur

See Also
getHibernateFlushMode(), Session#getHibernateFlushMode()
setHibernateFlushModeback to summary
public CommonQueryContract setHibernateFlushMode(FlushMode flushMode)

Set the current FlushMode in effect for this query.

Implementation Note

Setting to null ultimately indicates to use the FlushMode of the Session. Use FlushMode#MANUAL instead to indicate that no automatic flushing should occur.

See Also
getHibernateFlushMode(), Session#getHibernateFlushMode()
setHintback to summary
public CommonQueryContract setHint(String hintName, Object value)

Set a hint. The hints understood by Hibernate are enumerated by org.hibernate.jpa.AvailableHints.

See Also
org.hibernate.jpa.HibernateHints, org.hibernate.jpa.SpecHints
setParameterback to summary
public CommonQueryContract setParameter(String parameter, Object value)

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 forms which accepts a "type".

See Also
setParameter(String, Object, Class), setParameter(String, Object, BindableType)
setParameterback to summary
public <P> CommonQueryContract setParameter(String parameter, P value, Class<P> type)

Bind the given argument to a named query parameter using the given Class reference to attempt to infer the BindableType. If unable to infer an appropriate BindableType, fall back to setParameter(String, Object).

See Also
setParameter(String, Object, BindableType)
setParameterback to summary
public <P> CommonQueryContract setParameter(String parameter, P value, BindableType<P> type)

Bind the given argument to a named query parameter using the given BindableType.

setParameterback to summary
public CommonQueryContract setParameter(String parameter, Instant value, TemporalType temporalType)

Bind an Instant to the named query parameter using just the portion indicated by the given TemporalType.

setParameterback to summary
public CommonQueryContract setParameter(String parameter, Calendar value, TemporalType temporalType)
See Also
jakarta.persistence.Query#setParameter(String, Calendar, TemporalType)
setParameterback to summary
public CommonQueryContract setParameter(String parameter, Date value, TemporalType temporalType)
See Also
jakarta.persistence.Query#setParameter(String, Date, TemporalType)
setParameterback to summary
public CommonQueryContract setParameter(int parameter, Object value)

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 forms which accepts a "type".

See Also
setParameter(int, Object, Class), setParameter(int, Object, BindableType)
setParameterback to summary
public <P> CommonQueryContract setParameter(int parameter, P value, Class<P> type)

Bind the given argument to an ordinal query parameter using the given Class reference to attempt to infer the BindableType. If unable to infer an appropriate BindableType, fall back to setParameter(int, Object).

See Also
setParameter(int, Object, BindableType)
setParameterback to summary
public <P> CommonQueryContract setParameter(int parameter, P value, BindableType<P> type)

Bind the given argument to an ordinal query parameter using the given BindableType.

setParameterback to summary
public CommonQueryContract setParameter(int parameter, Instant value, TemporalType temporalType)

Bind an Instant to an ordinal query parameter using just the portion indicated by the given TemporalType.

setParameterback to summary
public CommonQueryContract setParameter(int parameter, Date value, TemporalType temporalType)
See Also
jakarta.persistence.Query#setParameter(int, Date, TemporalType)
setParameterback to summary
public CommonQueryContract setParameter(int parameter, Calendar value, TemporalType temporalType)
See Also
jakarta.persistence.Query#setParameter(int, Calendar, TemporalType)
setParameterback to summary
public <T> CommonQueryContract setParameter(QueryParameter<T> parameter, T value)

Bind an argument to the query parameter represented by the given QueryParameter.

If the type of the parameter cannot be inferred from the context in which it occurs, use one of the forms which accepts a "type".

Parameters
parameter:QueryParameter<T>

the query parameter memento

value:T

the argument, which might be null

Returns:CommonQueryContract

this, for method chaining

See Also
setParameter(QueryParameter, Object, BindableType)
setParameterback to summary
public <P> CommonQueryContract setParameter(QueryParameter<P> parameter, P value, Class<P> type)

Bind an argument to the query parameter represented by the given QueryParameter, using the given Class reference to attempt to infer the BindableType to use. If unable to infer an appropriate BindableType, fall back to setParameter(QueryParameter, Object).

Parameters
parameter:QueryParameter<P>

the query parameter memento

value:P

the argument, which might be null

type:Class<P>

a BindableType representing the type of the parameter

Returns:CommonQueryContract

this, for method chaining

See Also
setParameter(QueryParameter, Object, BindableType)
setParameterback to summary
public <P> CommonQueryContract setParameter(QueryParameter<P> parameter, P val, BindableType<P> type)

Bind an argument to the query parameter represented by the given QueryParameter, using the given BindableType.

Parameters
parameter:QueryParameter<P>

the query parameter memento

val:P

the argument, which might be null

type:BindableType<P>

a BindableType representing the type of the parameter

Returns:CommonQueryContract

this, for method chaining

setParameterback to summary
public <T> CommonQueryContract setParameter(Parameter<T> param, T value)
See Also
jakarta.persistence.Query#setParameter(Parameter, Object)
setParameterback to summary
public CommonQueryContract setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType)
See Also
jakarta.persistence.Query#setParameter(Parameter, Calendar, TemporalType)
setParameterback to summary
public CommonQueryContract setParameter(Parameter<Date> param, Date value, TemporalType temporalType)
See Also
jakarta.persistence.Query#setParameter(Parameter, Date, TemporalType)
setParameterListback to summary
public CommonQueryContract setParameterList(String parameter, Collection<E> values)

Bind multiple arguments to a named query parameter.

The "type mapping" for the binding is inferred from the type of the first collection element.

API Note

This is used for binding a list of values to an expression such as entity.field in (:values).

Returns:CommonQueryContract

this, for method chaining

See Also
setParameterList(java.lang.String, java.util.Collection, BindableType)
setParameterListback to summary
public <P> CommonQueryContract setParameterList(String parameter, Collection<? extends P> values, Class<P> javaType)

Bind multiple arguments to a named query parameter using the given Class reference to attempt to infer the BindableType If unable to infer an appropriate BindableType, fall back to setParameterList(String, Collection).

API Note

This is used for binding a list of values to an expression such as entity.field in (:values).

Returns:CommonQueryContract

this, for method chaining

See Also
setParameterList(java.lang.String, java.util.Collection, BindableType)
setParameterListback to summary
public <P> CommonQueryContract setParameterList(String parameter, Collection<? extends P> values, BindableType<P> type)

Bind multiple arguments to a named query parameter using the given BindableType.

API Note

This is used for binding a list of values to an expression such as entity.field in (:values).

Returns:CommonQueryContract

this, for method chaining

setParameterListback to summary
public CommonQueryContract setParameterList(String parameter, Object[] values)

Bind multiple arguments to a named query parameter.

The "type mapping" for the binding is inferred from the type of the first collection element

API Note

This is used for binding a list of values to an expression such as entity.field in (:values).

Returns:CommonQueryContract

this, for method chaining

setParameterListback to summary
public <P> CommonQueryContract 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 the BindableType to use. If unable to determine an appropriate BindableType, setParameterList(String, Collection) is used

API Note

This is used for binding a list of values to an expression such as entity.field in (:values).

Returns:CommonQueryContract

this, for method chaining

See Also
setParameterList(java.lang.String, Object[], BindableType)
setParameterListback to summary
public <P> CommonQueryContract setParameterList(String parameter, P[] values, BindableType<P> type)

Bind multiple arguments to a named query parameter using the given BindableType.

API Note

This is used for binding a list of values to an expression such as entity.field in (:values).

Returns:CommonQueryContract

this, for method chaining

setParameterListback to summary
public CommonQueryContract setParameterList(int parameter, Collection<E> values)

Bind multiple arguments to an ordinal query parameter.

The "type mapping" for the binding is inferred from the type of the first collection element

API Note

This is used for binding a list of values to an expression such as entity.field in (:values).

Returns:CommonQueryContract

this, for method chaining

setParameterListback to summary
public <P> CommonQueryContract setParameterList(int parameter, Collection<? extends P> values, Class<P> javaType)

Bind multiple arguments to an ordinal query parameter using the given Class reference to attempt to infer the BindableType. If unable to infer an appropriate BindableType, fall back to setParameterList(String, Collection).

API Note

This is used for binding a list of values to an expression such as entity.field in (:values).

Returns:CommonQueryContract

this, for method chaining

See Also
setParameterList(int, Collection, BindableType)
setParameterListback to summary
public <P> CommonQueryContract setParameterList(int parameter, Collection<? extends P> values, BindableType<P> type)

Bind multiple arguments to an ordinal query parameter using the given BindableType.

API Note

This is used for binding a list of values to an expression such as entity.field in (:values).

Returns:CommonQueryContract

this, for method chaining

setParameterListback to summary
public CommonQueryContract setParameterList(int parameter, Object[] values)

Bind multiple arguments to an ordinal query parameter.

The "type mapping" for the binding is inferred from the type of the first collection element

API Note

This is used for binding a list of values to an expression such as entity.field in (:values).

Returns:CommonQueryContract

this, for method chaining

setParameterListback to summary
public <P> CommonQueryContract setParameterList(int parameter, P[] values, Class<P> javaType)

Bind multiple arguments to an ordinal query parameter using the given Class reference to attempt to infer the BindableType. If unable to infer an appropriate BindableType, fall back to setParameterList(String, Collection).

API Note

This is used for binding a list of values to an expression such as entity.field in (:values).

Returns:CommonQueryContract

this, for method chaining

See Also
setParameterList(int, Object[], BindableType)
setParameterListback to summary
public <P> CommonQueryContract setParameterList(int parameter, P[] values, BindableType<P> type)

Bind multiple arguments to an ordinal query parameter using the given BindableType.

API Note

This is used for binding a list of values to an expression such as entity.field in (:values).

Returns:CommonQueryContract

this, for method chaining

setParameterListback to summary
public <P> CommonQueryContract setParameterList(QueryParameter<P> parameter, Collection<? extends P> values)

Bind multiple arguments to the query parameter represented by the given QueryParameter.

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:QueryParameter<P>

the parameter memento

values:Collection<? extends P>

a collection of arguments

Returns:CommonQueryContract

this, for method chaining

setParameterListback to summary
public <P> CommonQueryContract setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, Class<P> javaType)

Bind multiple arguments to the query parameter represented by the given QueryParameter using the given Class reference to attempt to infer the BindableType to use. If unable to infer an appropriate BindableType, fall back to using setParameterList(String, Collection).

API Note

This is used for binding a list of values to an expression such as entity.field in (:values).

Returns:CommonQueryContract

this, for method chaining

See Also
setParameterList(QueryParameter, java.util.Collection, BindableType)
setParameterListback to summary
public <P> CommonQueryContract setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, BindableType<P> type)

Bind multiple arguments to the query parameter represented by the given QueryParameter, using the given BindableType.

API Note

This is used for binding a list of values to an expression such as entity.field in (:values).

Returns:CommonQueryContract

this, for method chaining

setParameterListback to summary
public <P> CommonQueryContract setParameterList(QueryParameter<P> parameter, P[] values)

Bind multiple arguments to the query parameter represented by the given QueryParameter.

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:QueryParameter<P>

the parameter memento

values:P[]

a collection of arguments

Returns:CommonQueryContract

this, for method chaining

setParameterListback to summary
public <P> CommonQueryContract setParameterList(QueryParameter<P> parameter, P[] values, Class<P> javaType)

Bind multiple arguments to the query parameter represented by the given QueryParameter using the given Class reference to attempt to infer the BindableType to use. If unable to infer an appropriate BindableType, fall back to using setParameterList(String, Collection).

API Note

This is used for binding a list of values to an expression such as entity.field in (:values).

Returns:CommonQueryContract

this, for method chaining

See Also
setParameterList(QueryParameter, Object[], BindableType)
setParameterListback to summary
public <P> CommonQueryContract setParameterList(QueryParameter<P> parameter, P[] values, BindableType<P> type)

Bind multiple arguments to the query parameter represented by the given QueryParameter, using the given the BindableType.

API Note

This is used for binding a list of values to an expression such as entity.field in (:values).

Returns:CommonQueryContract

this, for method chaining

setPropertiesback to summary
public CommonQueryContract 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.

Parameters
bean:Object

any JavaBean or POJO

Returns:CommonQueryContract

this, for method chaining

setPropertiesback to summary
public CommonQueryContract setProperties(Map<K, V> bean)

Bind the values of the given Map to named parameters of the query, matching key names with parameter names and mapping value types to Hibernate types using heuristics.

Parameters
bean:Map<K, V>

a Map of names to arguments

Returns:CommonQueryContract

this, for method chaining

setTimeoutback to summary
public CommonQueryContract setTimeout(int timeout)

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.

A value of zero indicates no timeout.

Parameters
timeout:int

the timeout in seconds

Returns:CommonQueryContract

this, for method chaining

See Also
getTimeout()