Top Description Methods
org.hibernate.query

public Interface SelectionQuery<R>

extends CommonQueryContract
Known Direct Subinterfaces
org.hibernate.query.sqm.SqmSelectionQuery, org.hibernate.query.Query
Known Direct Implementers
org.hibernate.query.spi.AbstractSelectionQuery
Annotations
@Incubating
Imports
java.time.Instant, java.util.Calendar, .Collection, .Date, .List, .Map, .Optional, java.util.stream.Stream, jakarta.persistence.CacheRetrieveMode, .CacheStoreMode, .EntityGraph, .FlushModeType, .LockModeType, .Parameter, .TemporalType, org.hibernate.CacheMode, .FlushMode, .Incubating, .LockMode, .LockOptions, .NonUniqueResultException, .Remove, .ScrollMode, .ScrollableResults, .Session, .SessionFactory, .UnknownProfileException, org.hibernate.dialect.Dialect, org.hibernate.engine.profile.DefaultFetchProfile, org.hibernate.graph.GraphSemantic

Within the context of an active session, an instance of this type represents an executable selection query, that is, a select. It is a slimmed-down version of Query, providing only methods relevant to selection queries.

A SelectionQuery may be obtained from the org.hibernate.Session by calling:

A SelectionQuery controls how a query is executed, and allows arguments to be bound to its parameters.

A query may have explicit fetch joins, specified using the syntax join fetch in HQL, or via jakarta.persistence.criteria.From#fetch in the criteria API. Additional fetch joins may be added by:

The special built-in fetch profile named org.hibernate.defaultProfile adds a fetch join for every eager @ManyToOne or @OneToOne association belonging to an entity returned by the query.

Author
Steve Ebersole

Method Summary

Modifier and TypeMethod and Description
public SelectionQuery<R>
disableFetchProfile(String
the name of the fetch profile to be disabled
profileName
)

Disable the fetch profile with the given name in this session.

public SelectionQuery<R>
enableFetchProfile(String
the name of the fetch profile to be enabled
profileName
)

Enable the fetch profile for this query.

public CacheMode
getCacheMode()

Obtain the CacheMode in effect for this query.

public String
getCacheRegion()

Obtain the name of the second level query cache region in which query results will be stored (if they are cached, see the discussion on isCacheable() for more information).

public CacheRetrieveMode
public CacheStoreMode
public Integer

Returns:

The timeout in seconds
getFetchSize
()

Obtain the JDBC fetch size hint in effect for this query.

public int
getFirstResult()

The first row position to return from the query results.

public LockMode
getHibernateLockMode()

Get the root LockMode for the query

public LockModeType
getLockMode()

Get the root LockModeType for the query

public LockOptions
getLockOptions()

The LockOptions currently in effect for the query

public int
getMaxResults()

The max number of rows requested for the query results

public default List<R>

Returns:

the results as a list
getResultList
()

Execute the query and return the query results as a List.

public default Stream<R>

Returns:

The results as a Stream
getResultStream
()

Execute the query and return the query results as a Stream.

public R

Returns:

the single result, only if there is exactly one
getSingleResult
()

Execute the query and return the single result of the query, throwing an exception if the query returns no results.

public R

Returns:

the single result or null if there is no result to return
getSingleResultOrNull
()

Execute the query and return the single result of the query, or null if the query returns no results.

public boolean
isCacheable()

Should the results of the query be stored in the second level cache?

public boolean
isQueryPlanCacheable()

Should the query plan of the query be stored in the query plan cache?

public boolean

Returns:

true if the entities and proxies loaded by the query will be put in read-only mode; false otherwise (they will be modifiable)
isReadOnly
()

Should entities and proxies loaded by this Query be put in read-only mode?

public List<R>

Returns:

the result list
list
()

Execute the query and return the query results as a List.

public ScrollableResults<R>
scroll()

Returns scrollable access to the query results.

public ScrollableResults<R>
scroll(ScrollMode scrollMode)

Returns scrollable access to the query results.

public @Remove SelectionQuery<R>
setAliasSpecificLockMode(String alias, LockMode lockMode)

Deprecated since 6.2. use setLockMode(String, LockMode)
Specify a LockMode to apply to a specific alias defined in the query
public SelectionQuery<R>
setCacheable(boolean cacheable)

Enable/disable second level query (result) caching for this query.

public SelectionQuery<R>
setCacheMode(CacheMode cacheMode)

Set the current CacheMode in effect for this query.

public SelectionQuery<R>
setCacheRegion(String cacheRegion)

Set the name of the cache region where query results should be cached (assuming isCacheable).

public SelectionQuery<R>
public SelectionQuery<R>
public SelectionQuery<R>
setComment(String comment)

Redeclares org.hibernate.query.CommonQueryContract.setComment.

Set a comment for this query.
public SelectionQuery<R>
setEntityGraph(EntityGraph<R> graph, GraphSemantic semantic)

Apply an EntityGraph to the query.

public SelectionQuery<R>

Returns:

this, for method chaining
setFetchSize
(int
the fetch size hint
fetchSize
)

Sets a JDBC fetch size hint for the query.

public SelectionQuery<R>
setFirstResult(int startPosition)

Set the first row position to return from the query results.

public SelectionQuery<R>
setFlushMode(FlushModeType flushMode)

Redeclares org.hibernate.query.CommonQueryContract.setFlushMode.

Set the FlushMode in to use for this query.
public SelectionQuery<R>
setFollowOnLocking(boolean enable)

Specifies whether follow-on locking should be applied

public SelectionQuery<R>
setHibernateFlushMode(FlushMode flushMode)

Redeclares org.hibernate.query.CommonQueryContract.setHibernateFlushMode.

Set the current FlushMode in effect for this query.
public SelectionQuery<R>
setHibernateLockMode(LockMode lockMode)

Specify the root LockMode for the query

public SelectionQuery<R>
setHint(String hintName, Object value)

Redeclares org.hibernate.query.CommonQueryContract.setHint.

Set a hint.
public SelectionQuery<R>
setLockMode(LockModeType lockMode)

Specify the root LockModeType for the query

public SelectionQuery<R>
setLockMode(String alias, LockMode lockMode)

Specify a LockMode to apply to a specific alias defined in the query

public SelectionQuery<R>
setMaxResults(int maxResult)

Set the max number of rows requested for the query results.

public SelectionQuery<R>
setOrder(List<Order<? super R>>
one or more instances of Order
orderList
)

If the result type of this query is an entity class, add one or more rules for ordering the query results.

public SelectionQuery<R>
setOrder(Order<? super R>
an instance of Order
order
)

If the result type of this query is an entity class, add a rule for ordering the query results.

public SelectionQuery<R>
setPage(Page page)

Set the page of results to return.

public SelectionQuery<R>
setParameter(String name, Object value)

Redeclares org.hibernate.query.CommonQueryContract.setParameter.

Bind the given argument to a named query parameter.
public <P> SelectionQuery<R>
setParameter(String name, P value, Class<P> type)

Redeclares org.hibernate.query.CommonQueryContract.setParameter.

Bind the given argument to a named query parameter using the given Class reference to attempt to infer the BindableType.
public <P> SelectionQuery<R>
setParameter(String name, P value, BindableType<P> type)

Redeclares org.hibernate.query.CommonQueryContract.setParameter.

Bind the given argument to a named query parameter using the given BindableType.
public SelectionQuery<R>
setParameter(String name, Instant value, TemporalType temporalType)

Redeclares org.hibernate.query.CommonQueryContract.setParameter.

Bind an Instant to the named query parameter using just the portion indicated by the given TemporalType.
public SelectionQuery<R>
public SelectionQuery<R>
public SelectionQuery<R>
setParameter(int position, Object value)

Redeclares org.hibernate.query.CommonQueryContract.setParameter.

Bind the given argument to an ordinal query parameter.
public <P> SelectionQuery<R>
setParameter(int position, P value, Class<P> type)

Redeclares org.hibernate.query.CommonQueryContract.setParameter.

Bind the given argument to an ordinal query parameter using the given Class reference to attempt to infer the BindableType.
public <P> SelectionQuery<R>
setParameter(int position, P value, BindableType<P> type)

Redeclares org.hibernate.query.CommonQueryContract.setParameter.

Bind the given argument to an ordinal query parameter using the given BindableType.
public SelectionQuery<R>
setParameter(int position, Instant value, TemporalType temporalType)

Redeclares org.hibernate.query.CommonQueryContract.setParameter.

Bind an Instant to an ordinal query parameter using just the portion indicated by the given TemporalType.
public SelectionQuery<R>
public SelectionQuery<R>
public <T> SelectionQuery<R>
setParameter(QueryParameter<T>
the query parameter memento
parameter
,
T
the argument, which might be null
value
)

Redeclares org.hibernate.query.CommonQueryContract.setParameter.

Bind an argument to the query parameter represented by the given QueryParameter.
public <P> SelectionQuery<R>
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
)

Redeclares org.hibernate.query.CommonQueryContract.setParameter.

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> SelectionQuery<R>
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
)

Redeclares org.hibernate.query.CommonQueryContract.setParameter.

Bind an argument to the query parameter represented by the given QueryParameter, using the given BindableType.
public <T> SelectionQuery<R>
public SelectionQuery<R>
public SelectionQuery<R>
public SelectionQuery<R>
setParameterList(String name, Collection<E> values)

Redeclares org.hibernate.query.CommonQueryContract.setParameterList.

Bind multiple arguments to a named query parameter.
public <P> SelectionQuery<R>
setParameterList(String name, Collection<? extends P> values, Class<P> javaType)

Redeclares org.hibernate.query.CommonQueryContract.setParameterList.

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> SelectionQuery<R>
setParameterList(String name, Collection<? extends P> values, BindableType<P> type)

Redeclares org.hibernate.query.CommonQueryContract.setParameterList.

Bind multiple arguments to a named query parameter using the given BindableType.
public SelectionQuery<R>
setParameterList(String name, Object[] values)

Redeclares org.hibernate.query.CommonQueryContract.setParameterList.

Bind multiple arguments to a named query parameter.
public <P> SelectionQuery<R>
setParameterList(String name, P[] values, Class<P> javaType)

Redeclares org.hibernate.query.CommonQueryContract.setParameterList.

Bind multiple arguments to a named query parameter using the given Class reference to attempt to determine the BindableType to use.
public <P> SelectionQuery<R>
setParameterList(String name, P[] values, BindableType<P> type)

Redeclares org.hibernate.query.CommonQueryContract.setParameterList.

Bind multiple arguments to a named query parameter using the given BindableType.
public SelectionQuery<R>
setParameterList(int position, Collection<E> values)

Redeclares org.hibernate.query.CommonQueryContract.setParameterList.

Bind multiple arguments to an ordinal query parameter.
public <P> SelectionQuery<R>
setParameterList(int position, Collection<? extends P> values, Class<P> javaType)

Redeclares org.hibernate.query.CommonQueryContract.setParameterList.

Bind multiple arguments to an ordinal query parameter using the given Class reference to attempt to infer the BindableType.
public <P> SelectionQuery<R>
setParameterList(int position, Collection<? extends P> values, BindableType<P> type)

Redeclares org.hibernate.query.CommonQueryContract.setParameterList.

Bind multiple arguments to an ordinal query parameter using the given BindableType.
public SelectionQuery<R>
setParameterList(int position, Object[] values)

Redeclares org.hibernate.query.CommonQueryContract.setParameterList.

Bind multiple arguments to an ordinal query parameter.
public <P> SelectionQuery<R>
setParameterList(int position, P[] values, Class<P> javaType)

Redeclares org.hibernate.query.CommonQueryContract.setParameterList.

Bind multiple arguments to an ordinal query parameter using the given Class reference to attempt to infer the BindableType.
public <P> SelectionQuery<R>
setParameterList(int position, P[] values, BindableType<P> type)

Redeclares org.hibernate.query.CommonQueryContract.setParameterList.

Bind multiple arguments to an ordinal query parameter using the given BindableType.
public <P> SelectionQuery<R>
setParameterList(QueryParameter<P>
the parameter memento
parameter
,
Collection<? extends P>
a collection of arguments
values
)

Redeclares org.hibernate.query.CommonQueryContract.setParameterList.

Bind multiple arguments to the query parameter represented by the given QueryParameter.
public <P> SelectionQuery<R>
setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, Class<P> javaType)

Redeclares org.hibernate.query.CommonQueryContract.setParameterList.

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> SelectionQuery<R>
setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, BindableType<P> type)

Redeclares org.hibernate.query.CommonQueryContract.setParameterList.

Bind multiple arguments to the query parameter represented by the given QueryParameter, using the given BindableType.
public <P> SelectionQuery<R>
setParameterList(QueryParameter<P>
the parameter memento
parameter
,
P[]
a collection of arguments
values
)

Redeclares org.hibernate.query.CommonQueryContract.setParameterList.

Bind multiple arguments to the query parameter represented by the given QueryParameter.
public <P> SelectionQuery<R>
setParameterList(QueryParameter<P> parameter, P[] values, Class<P> javaType)

Redeclares org.hibernate.query.CommonQueryContract.setParameterList.

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> SelectionQuery<R>
setParameterList(QueryParameter<P> parameter, P[] values, BindableType<P> type)

Redeclares org.hibernate.query.CommonQueryContract.setParameterList.

Bind multiple arguments to the query parameter represented by the given QueryParameter, using the given the BindableType.
public SelectionQuery<R>
setProperties(Object
any JavaBean or POJO
bean
)

Redeclares org.hibernate.query.CommonQueryContract.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.
public SelectionQuery<R>
setProperties(Map<K, V>
a Map of names to arguments
bean
)

Redeclares org.hibernate.query.CommonQueryContract.setProperties.

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 SelectionQuery<R>
setQueryPlanCacheable(boolean queryPlanCacheable)

Enable/disable query plan caching for this query.

public SelectionQuery<R>

Returns:

this, for method chaining
setReadOnly
(boolean
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 mode
readOnly
)

Set the read-only/modifiable mode for entities and proxies loaded by this Query.

public SelectionQuery<R>
setTimeout(int
the timeout in seconds
timeout
)

Redeclares org.hibernate.query.CommonQueryContract.setTimeout.

Set the query timeout in seconds.
public default Stream<R>

Returns:

The results as a Stream
stream
()

Execute the query and return the query results as a Stream.

public R

Returns:

the single result or null
uniqueResult
()

Execute the query and return the single result of the query, or null if the query returns no results.

public Optional<R>

Returns:

the single result as an Optional
uniqueResultOptional
()

Execute the query and return the single result of the query, as an Optional.

Inherited from org.hibernate.query.CommonQueryContract:
getCommentgetFlushModegetHibernateFlushModegetTimeout