R
- The query result type (for typed queries)public interface Query<R> extends TypedQuery<R>, CommonQueryContract
Modifier and Type | Method and Description |
---|---|
Query<R> |
addQueryHint(String hint)
Add a DB query hint to the SQL.
|
default Query<R> |
applyFetchGraph(RootGraph graph)
Apply the given graph using fetch semantics
|
Query<R> |
applyGraph(RootGraph<?> graph,
GraphSemantic semantic)
Apply the given graph using the given semantic
|
default Query<R> |
applyLoadGraph(RootGraph graph)
Apply the given graph using load semantics
|
String |
getComment()
Obtain the comment currently associated with this query.
|
LockOptions |
getLockOptions()
Obtains the LockOptions in effect for this query.
|
ParameterMetadata |
getParameterMetadata()
Access to information about query parameters.
|
QueryOptions |
getQueryOptions()
Get the execution options for this Query.
|
String |
getQueryString()
Get the query string.
|
default List<R> |
getResultList() |
SharedSessionContract |
getSession()
Get the QueryProducer this Query originates from.
|
default R |
getSingleResult() |
List<R> |
list()
Return the query results as a List.
|
ScrollableResults<R> |
scroll()
Returns scrollable access to the query results.
|
ScrollableResults<R> |
scroll(ScrollMode scrollMode)
Returns scrollable access to the query results.
|
Query<R> |
setCacheable(boolean cacheable)
Enable/disable second level query (result) caching for this query.
|
Query<R> |
setCacheMode(CacheMode cacheMode)
(Re)set the current CacheMode in effect for this query.
|
Query<R> |
setCacheRegion(String cacheRegion)
Set the name of the cache region where query results should be cached (if cached at all).
|
Query<R> |
setComment(String comment)
Set the comment for this query.
|
Query<R> |
setFetchSize(int fetchSize)
Sets a JDBC fetch size hint for the query.
|
Query<R> |
setFirstResult(int startPosition) |
Query<R> |
setFlushMode(FlushModeType flushMode) |
Query<R> |
setHibernateFlushMode(FlushMode flushMode)
(Re)set the current FlushMode in effect for this query.
|
Query<R> |
setHint(String hintName,
Object value) |
Query<R> |
setLockMode(LockModeType lockMode) |
Query<R> |
setLockMode(String alias,
LockMode lockMode)
Set the LockMode to use for specific alias (as defined in the query's FROM clause).
|
Query<R> |
setLockOptions(LockOptions lockOptions)
Set the lock options for the query.
|
Query<R> |
setMaxResults(int maxResult) |
Query<R> |
setParameter(int position,
Calendar value,
TemporalType temporalType) |
Query<R> |
setParameter(int position,
Date value,
TemporalType temporalType) |
Query<R> |
setParameter(int position,
Instant value,
TemporalType temporalType) |
Query<R> |
setParameter(int position,
LocalDateTime value,
TemporalType temporalType) |
Query<R> |
setParameter(int position,
Object value)
Bind a positional query parameter using its inferred Type.
|
Query<R> |
setParameter(int position,
Object val,
AllowableParameterType type)
Bind a value to a JDBC-style query parameter.
|
Query<R> |
setParameter(int position,
OffsetDateTime value,
TemporalType temporalType) |
<P> Query<R> |
setParameter(int position,
P val,
TemporalType temporalType)
Bind a positional query parameter as some form of date/time using
the indicated temporal-type.
|
Query<R> |
setParameter(int position,
ZonedDateTime value,
TemporalType temporalType) |
Query<R> |
setParameter(Parameter<Calendar> param,
Calendar value,
TemporalType temporalType) |
Query<R> |
setParameter(Parameter<Date> param,
Date value,
TemporalType temporalType) |
Query<R> |
setParameter(Parameter<Instant> param,
Instant value,
TemporalType temporalType) |
Query<R> |
setParameter(Parameter<LocalDateTime> param,
LocalDateTime value,
TemporalType temporalType) |
Query<R> |
setParameter(Parameter<OffsetDateTime> param,
OffsetDateTime value,
TemporalType temporalType) |
<T> Query<R> |
setParameter(Parameter<T> param,
T value) |
Query<R> |
setParameter(Parameter<ZonedDateTime> param,
ZonedDateTime value,
TemporalType temporalType) |
<P> Query<R> |
setParameter(QueryParameter<P> parameter,
P val,
AllowableParameterType type)
Bind a query parameter using the supplied Type
|
<P> Query<R> |
setParameter(QueryParameter<P> parameter,
P val,
TemporalType temporalType)
Bind a query parameter as some form of date/time using the indicated
temporal-type.
|
<T> Query<R> |
setParameter(QueryParameter<T> parameter,
T val)
Bind a query parameter using its inferred Type.
|
Query<R> |
setParameter(String name,
Calendar value,
TemporalType temporalType) |
Query<R> |
setParameter(String name,
Date value,
TemporalType temporalType) |
Query<R> |
setParameter(String name,
Instant value,
TemporalType temporalType) |
Query<R> |
setParameter(String name,
LocalDateTime value,
TemporalType temporalType) |
Query<R> |
setParameter(String name,
Object value)
Bind a named query parameter using its inferred Type.
|
Query<R> |
setParameter(String name,
Object val,
AllowableParameterType type)
Bind a named query parameter using the supplied Type
|
Query<R> |
setParameter(String name,
OffsetDateTime value,
TemporalType temporalType) |
<P> Query<R> |
setParameter(String name,
P val,
TemporalType temporalType)
Bind a named query parameter as some form of date/time using
the indicated temporal-type.
|
Query<R> |
setParameter(String name,
ZonedDateTime value,
TemporalType temporalType) |
Query<R> |
setParameterList(int position,
Collection values)
Bind multiple values to a positional query parameter.
|
Query<R> |
setParameterList(int position,
Collection values,
AllowableParameterType type)
Bind multiple values to a positional query parameter.
|
Query<R> |
setParameterList(int position,
Collection values,
Class type)
Bind multiple values to a positional query parameter.
|
Query<R> |
setParameterList(int position,
Object[] values)
Bind multiple values to a named query parameter.
|
Query<R> |
setParameterList(int position,
Object[] values,
AllowableParameterType type)
Bind multiple values to a named query parameter.
|
<P> Query<R> |
setParameterList(QueryParameter<P> parameter,
Collection<P> values)
Bind multiple values to a query parameter using its inferred Type.
|
Query<R> |
setParameterList(String name,
Collection values)
Bind multiple values to a named query parameter.
|
Query<R> |
setParameterList(String name,
Collection values,
AllowableParameterType type)
Bind multiple values to a named query parameter.
|
Query<R> |
setParameterList(String name,
Collection values,
Class type)
Bind multiple values to a named query parameter.
|
Query<R> |
setParameterList(String name,
Object[] values)
Bind multiple values to a named query parameter.
|
Query<R> |
setParameterList(String name,
Object[] values,
AllowableParameterType type)
Bind multiple values to a named query parameter.
|
Query<R> |
setProperties(Map bean)
Bind the values of the given Map for each named parameters of the query,
matching key names with parameter names and mapping value types to
Hibernate types using heuristics.
|
Query<R> |
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.
|
Query<R> |
setReadOnly(boolean readOnly)
Set the read-only/modifiable mode for entities and proxies
loaded by this Query.
|
Query<R> |
setResultListTransformer(ResultListTransformer transformer) |
default Query<R> |
setResultTransformer(ResultTransformer transformer)
Deprecated.
|
Query<R> |
setTimeout(int timeout)
Set the query timeout in seconds.
|
Query<R> |
setTupleTransformer(TupleTransformer<R> transformer) |
Stream<R> |
stream()
Retrieve a Stream over the query results.
|
R |
uniqueResult()
Convenience method to return a single instance that matches
the query, or
null if the query returns no results. |
Optional<R> |
uniqueResultOptional() |
getResultStream
executeUpdate, getFirstResult, getFlushMode, getHints, getLockMode, getMaxResults, getParameter, getParameter, getParameter, getParameter, getParameters, getParameterValue, getParameterValue, getParameterValue, isBound, unwrap
getCacheMode, getCacheRegion, getFetchSize, getHibernateFlushMode, getTimeout, isCacheable, isReadOnly
SharedSessionContract getSession()
String getQueryString()
null
or some other
less-than-useful return because the source of the query might not be a
String (e.g., a Criteria query).Query<R> applyGraph(RootGraph<?> graph, GraphSemantic semantic)
graph
- The graph the apply.semantic
- The semantic to use when applying the graphdefault Query<R> applyFetchGraph(RootGraph graph)
applyGraph(RootGraph, GraphSemantic)
using
GraphSemantic.FETCH
as the semanticdefault Query<R> applyLoadGraph(RootGraph graph)
applyGraph(RootGraph, GraphSemantic)
using
GraphSemantic.LOAD
as the semanticScrollableResults<R> scroll()
scroll(ScrollMode)
using Dialect.defaultScrollMode()
ResultSet
scrolling supportScrollableResults<R> scroll(ScrollMode scrollMode)
ResultSet
scrolling supportList<R> list()
default List<R> getResultList()
getResultList
in interface Query
getResultList
in interface TypedQuery<R>
R uniqueResult()
null
if the query returns no results.NonUniqueResultException
- if there is more than one matching resultdefault R getSingleResult()
getSingleResult
in interface Query
getSingleResult
in interface TypedQuery<R>
Stream<R> stream()
You should call BaseStream.close()
after processing the stream
so that the underlying resources are deallocated right away.
String getComment()
hibernate.use_sql_comments
config setting), this comment will also be added
to the SQL query sent to the database. Often useful for identifying the source of troublesome queries on the
database side.Query<R> setComment(String comment)
comment
- The human-readable commentthis
, for method chaininggetComment()
Query<R> addQueryHint(String hint)
QueryHint
and Query.getHints()
, which is
specific to the JPA implementation and ignores DB vendor-specific hints.
Instead, these are intended solely for the vendor-specific hints, such
as Oracle's optimizers. Multiple query hints are supported; the Dialect
will determine concatenation and placement.hint
- The database specific query hint to add.LockOptions getLockOptions()
LockOptions
Query<R> setLockOptions(LockOptions lockOptions)
setLockMode(String, LockMode)
.lockOptions
- The lock options to apply to the query.this
, for method chaininggetLockOptions()
Query<R> setLockMode(String alias, LockMode lockMode)
The alias-specific lock modes specified here are added to the query's internal
LockOptions
.
The effect of these alias-specific LockModes is somewhat dependent on the driver/database in use. Generally
speaking, for maximum portability, this method should only be used to mark that the rows corresponding to
the given alias should be included in pessimistic locking (LockMode.PESSIMISTIC_WRITE
).
alias
- a query alias, or "this"
for a collection filterlockMode
- The lock mode to apply.this
, for method chaininggetLockOptions()
Query<R> setTupleTransformer(TupleTransformer<R> transformer)
Query<R> setResultListTransformer(ResultListTransformer transformer)
QueryOptions getQueryOptions()
QueryOptions
. This is
important because it gives access to any primitive data in their wrapper
forms rather than the primitive forms as required by JPA. For example, that
allows use to know whether a specific value has been set at all by the Query
consumer.ParameterMetadata getParameterMetadata()
<T> Query<R> setParameter(QueryParameter<T> parameter, T val)
setParameter(QueryParameter, Object, AllowableParameterType)
should be used insteadparameter
- The query parameter mementoval
- the possibly-null parameter valuethis
, for method chainingQuery<R> setParameter(String name, Object val, AllowableParameterType type)
name
- the name of the parameterval
- the possibly-null parameter valuetype
- the Hibernate allowable parameter typethis
, for method chainingQuery<R> setParameter(int position, Object val, AllowableParameterType type)
position
- the position of the parameter in the query
string, numbered from 0.val
- the possibly-null parameter valuetype
- the Hibernate allowable parameter typethis
, for method chaining<P> Query<R> setParameter(String name, P val, TemporalType temporalType)
name
- the parameter nameval
- the possibly-null parameter valuetemporalType
- the temporal-type to use in binding the date/timethis
, for method chaining<P> Query<R> setParameter(int position, P val, TemporalType temporalType)
position
- the position of the parameter in the query
string, numbered from 0.val
- the possibly-null parameter valuetemporalType
- the temporal-type to use in binding the date/timethis
, for method chaining<P> Query<R> setParameter(QueryParameter<P> parameter, P val, TemporalType temporalType)
parameter
- The query parameter mementoval
- the possibly-null parameter valuetemporalType
- the temporal-type to use in binding the date/timethis
, for method chaining<P> Query<R> setParameter(QueryParameter<P> parameter, P val, AllowableParameterType type)
parameter
- The query parameter mementoval
- the possibly-null parameter valuetype
- the Hibernate allowable parameter typethis
, for method chainingQuery<R> setParameter(Parameter<Instant> param, Instant value, TemporalType temporalType)
Query<R> setParameter(Parameter<LocalDateTime> param, LocalDateTime value, TemporalType temporalType)
Query<R> setParameter(Parameter<ZonedDateTime> param, ZonedDateTime value, TemporalType temporalType)
Query<R> setParameter(Parameter<OffsetDateTime> param, OffsetDateTime value, TemporalType temporalType)
Query<R> setParameter(String name, Instant value, TemporalType temporalType)
Query<R> setParameter(String name, LocalDateTime value, TemporalType temporalType)
Query<R> setParameter(String name, ZonedDateTime value, TemporalType temporalType)
Query<R> setParameter(String name, OffsetDateTime value, TemporalType temporalType)
Query<R> setParameter(int position, Instant value, TemporalType temporalType)
Query<R> setParameter(int position, LocalDateTime value, TemporalType temporalType)
Query<R> setParameter(int position, ZonedDateTime value, TemporalType temporalType)
Query<R> setParameter(int position, OffsetDateTime value, TemporalType temporalType)
Query<R> setHibernateFlushMode(FlushMode flushMode)
CommonQueryContract
setHibernateFlushMode
in interface CommonQueryContract
flushMode
- The new FlushMode to use.this
, for method chainingSession.getHibernateFlushMode()
,
CommonQueryContract.getHibernateFlushMode()
Query<R> setCacheable(boolean cacheable)
CommonQueryContract
setCacheable
in interface CommonQueryContract
cacheable
- Should the query results be cacheable?this
, for method chainingCommonQueryContract.isCacheable()
Query<R> setCacheRegion(String cacheRegion)
CommonQueryContract
setCacheRegion
in interface CommonQueryContract
cacheRegion
- the name of a query cache region, or null
to indicate that the default region
should be used.this
, for method chainingCommonQueryContract.getCacheRegion()
Query<R> setCacheMode(CacheMode cacheMode)
CommonQueryContract
setCacheMode
in interface CommonQueryContract
cacheMode
- The new CacheMode to use.this
, for method chainingCommonQueryContract.getCacheMode()
Query<R> setTimeout(int timeout)
CommonQueryContract
setTimeout
in interface CommonQueryContract
timeout
- the timeout in secondsthis
, for method chainingCommonQueryContract.getTimeout()
Query<R> setFetchSize(int fetchSize)
CommonQueryContract
setFetchSize
in interface CommonQueryContract
fetchSize
- the fetch size hintthis
, for method chainingCommonQueryContract.getFetchSize()
Query<R> setReadOnly(boolean readOnly)
CommonQueryContract
setReadOnly
in interface CommonQueryContract
readOnly
- true
indicates that entities and proxies loaded by the query
are to be put in read-only mode; false
indicates that entities and proxies
loaded by the query will be put in modifiable modethis
, for method chainingTo set the default read-only/modifiable setting used for
entities and proxies that are loaded into the session:
,
PersistenceContext.setDefaultReadOnly(boolean)
,
Read-only entities are not dirty-checked and snapshots of persistent
state are not maintained. Read-only entities can be modified, but
changes are not persisted.
When a proxy is initialized, the loaded entity will have the same
read-only/modifiable setting as the uninitialized
proxy has, regardless of the session's current setting.
The read-only/modifiable setting has no impact on entities/proxies
returned by the query that existed in the session beforeQuery the query was executed.
Query<R> setMaxResults(int maxResult)
setMaxResults
in interface Query
setMaxResults
in interface TypedQuery<R>
Query<R> setFirstResult(int startPosition)
setFirstResult
in interface Query
setFirstResult
in interface TypedQuery<R>
Query<R> setHint(String hintName, Object value)
setHint
in interface Query
setHint
in interface TypedQuery<R>
Query<R> setFlushMode(FlushModeType flushMode)
setFlushMode
in interface Query
setFlushMode
in interface TypedQuery<R>
Query<R> setLockMode(LockModeType lockMode)
setLockMode
in interface Query
setLockMode
in interface TypedQuery<R>
Query<R> setParameter(String name, Object value)
setParameter(String, Object, AllowableParameterType)
should be used insteadsetParameter
in interface Query
setParameter
in interface TypedQuery<R>
name
- the parameter namevalue
- the (possibly-null) parameter valuethis
, for method chainingQuery<R> setParameter(int position, Object value)
setParameter(int, Object, AllowableParameterType)
should be used insteadsetParameter
in interface Query
setParameter
in interface TypedQuery<R>
position
- the position of the parameter in the query
string, numbered from 0.value
- the possibly-null parameter valuethis
, for method chaining<T> Query<R> setParameter(Parameter<T> param, T value)
setParameter
in interface Query
setParameter
in interface TypedQuery<R>
Query<R> setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType)
setParameter
in interface Query
setParameter
in interface TypedQuery<R>
Query<R> setParameter(Parameter<Date> param, Date value, TemporalType temporalType)
setParameter
in interface Query
setParameter
in interface TypedQuery<R>
Query<R> setParameter(String name, Calendar value, TemporalType temporalType)
setParameter
in interface Query
setParameter
in interface TypedQuery<R>
Query<R> setParameter(String name, Date value, TemporalType temporalType)
setParameter
in interface Query
setParameter
in interface TypedQuery<R>
Query<R> setParameter(int position, Calendar value, TemporalType temporalType)
setParameter
in interface Query
setParameter
in interface TypedQuery<R>
Query<R> setParameter(int position, Date value, TemporalType temporalType)
setParameter
in interface Query
setParameter
in interface TypedQuery<R>
<P> Query<R> setParameterList(QueryParameter<P> parameter, Collection<P> values)
parameter
- the parameter mementovalues
- a collection of values to listthis
, for method chainingQuery<R> setParameterList(String name, Collection values)
name
- the name of the parametervalues
- a collection of values to listthis
, for method chainingQuery<R> setParameterList(int position, Collection values)
position
- the parameter positional labelvalues
- a collection of values to listthis
, for method chainingQuery<R> setParameterList(String name, Collection values, Class type)
name
- the name of the parametervalues
- a collection of values to listthis
, for method chainingQuery<R> setParameterList(int position, Collection values, Class type)
position
- the parameter positional labelvalues
- a collection of values to listthis
, for method chainingQuery<R> setParameterList(String name, Collection values, AllowableParameterType type)
name
- the name of the parametervalues
- a collection of values to listtype
- the Hibernate allowable parameter type of the valuesthis
, for method chainingQuery<R> setParameterList(int position, Collection values, AllowableParameterType type)
position
- the parameter positional labelvalues
- a collection of values to listtype
- the Hibernate allowable parameter type of the valuesthis
, for method chainingQuery<R> setParameterList(String name, Object[] values, AllowableParameterType type)
name
- the name of the parametervalues
- a collection of values to listtype
- the Hibernate type of the valuesthis
, for method chainingQuery<R> setParameterList(int position, Object[] values, AllowableParameterType type)
position
- the parameter positional labelvalues
- a collection of values to listtype
- the Hibernate type of the valuesthis
, for method chainingQuery<R> setParameterList(String name, Object[] values)
name
- the name of the parametervalues
- a collection of values to listthis
, for method chainingQuery<R> setParameterList(int position, Object[] values)
position
- the parameter positional labelvalues
- a collection of values to listthis
, for method chainingQuery<R> setProperties(Object bean)
bean
- any JavaBean or POJOthis
, for method chainingQuery<R> setProperties(Map bean)
bean
- a java.util.Mapthis
, for method chaining@Deprecated default Query<R> setResultTransformer(ResultTransformer transformer)
setTupleTransformer(org.hibernate.query.TupleTransformer<R>)
or setResultListTransformer(org.hibernate.query.ResultListTransformer)
Copyright © 2001-2021 Red Hat, Inc. All Rights Reserved.