public static interface Mutiny.Session extends Mutiny.Closeable
Session
interface, allowing a reactive style of interaction with the database.
The semantics of operations on this interface are identical to the
semantics of the similarly-named operations of Session
, except
that the operations are performed asynchronously, returning a Uni
without blocking the calling thread.
Entities associated with an Session
do not support transparent
lazy association fetching. Instead, fetch(Object)
should be used
to explicitly request asynchronous fetching of an association, or the
association should be fetched eagerly when the entity is first retrieved,
for example, by:
enabling a fetch profile
,
EntityGraph
, or
join fetch
clause in a HQL query.
Session
Modifier and Type | Method and Description |
---|---|
Mutiny.Session |
clear()
Completely clear the session.
|
boolean |
contains(Object entity)
Determine if the given instance belongs to this persistence context.
|
<T> EntityGraph<T> |
createEntityGraph(Class<T> rootType)
Create a new mutable
EntityGraph |
<T> EntityGraph<T> |
createEntityGraph(Class<T> rootType,
String graphName)
Create a new mutable copy of a named
EntityGraph |
<R> Mutiny.Query<R> |
createNamedQuery(String queryName)
Create an instance of
Mutiny.Query for the named query. |
<R> Mutiny.Query<R> |
createNamedQuery(String queryName,
Class<R> resultType)
Create an instance of
Mutiny.Query for the named query. |
<R> Mutiny.Query<R> |
createNativeQuery(String queryString)
Create an instance of
Mutiny.Query for the given SQL query string,
or SQL update, insert, or delete statement. |
<R> Mutiny.Query<R> |
createNativeQuery(String queryString,
AffectedEntities affectedEntities)
Create an instance of
Mutiny.Query for the given SQL query string,
or SQL update, insert, or delete statement. |
<R> Mutiny.Query<R> |
createNativeQuery(String queryString,
Class<R> resultType)
Create an instance of
Mutiny.Query for the given SQL query
string, using the given resultType to interpret the results. |
<R> Mutiny.Query<R> |
createNativeQuery(String queryString,
Class<R> resultType,
AffectedEntities affectedEntities)
Create an instance of
Mutiny.Query for the given SQL query
string, using the given resultType to interpret the results. |
<R> Mutiny.Query<R> |
createNativeQuery(String queryString,
ResultSetMapping<R> resultSetMapping)
Create an instance of
Mutiny.Query for the given SQL query string,
using the given ResultSetMapping to interpret the result set. |
<R> Mutiny.Query<R> |
createNativeQuery(String queryString,
ResultSetMapping<R> resultSetMapping,
AffectedEntities affectedEntities)
Create an instance of
Mutiny.Query for the given SQL query string,
using the given ResultSetMapping to interpret the result set. |
<R> Mutiny.Query<R> |
createQuery(CriteriaDelete<R> criteriaDelete)
Create an instance of
Mutiny.Query for the given criteria delete. |
<R> Mutiny.Query<R> |
createQuery(CriteriaQuery<R> criteriaQuery)
Create an instance of
Mutiny.Query for the given criteria query. |
<R> Mutiny.Query<R> |
createQuery(CriteriaUpdate<R> criteriaUpdate)
Create an instance of
Mutiny.Query for the given criteria update. |
<R> Mutiny.Query<R> |
createQuery(String queryString)
Create an instance of
Mutiny.Query for the given HQL/JPQL query
string or HQL/JPQL update or delete statement. |
<R> Mutiny.Query<R> |
createQuery(String queryString,
Class<R> resultType)
Create an instance of
Mutiny.Query for the given HQL/JPQL query
string. |
Mutiny.Transaction |
currentTransaction()
Obtain the transaction currently associated with this session,
if any.
|
Mutiny.Session |
detach(Object entity)
Remove this instance from the session cache.
|
Mutiny.Session |
disableFetchProfile(String name)
Disable a particular fetch profile on this session, or do nothing if
the requested fetch profile is not enabled.
|
void |
disableFilter(String filterName)
Disable the named filter for this session.
|
Mutiny.Session |
enableFetchProfile(String name)
Enable a particular fetch profile on this session, or do nothing if
requested fetch profile is already enabled.
|
org.hibernate.Filter |
enableFilter(String filterName)
Enable the named filter for this session.
|
<E,T> io.smallrye.mutiny.Uni<T> |
fetch(E entity,
Attribute<E,T> field)
Fetch a lazy property of the given entity, identified by a JPA
attribute metamodel . |
<T> io.smallrye.mutiny.Uni<T> |
fetch(T association)
Asynchronously fetch an association that's configured for lazy loading.
|
<T> io.smallrye.mutiny.Uni<T> |
find(Class<T> entityClass,
Identifier<T> naturalId)
Asynchronously return the persistent instance of the given entity
class with the given natural identifier, or null if there is no
such persistent instance.
|
<T> io.smallrye.mutiny.Uni<List<T>> |
find(Class<T> entityClass,
Object... ids)
Asynchronously return the persistent instances of the given entity
class with the given identifiers, or null if there is no such
persistent instance.
|
<T> io.smallrye.mutiny.Uni<T> |
find(Class<T> entityClass,
Object id)
Asynchronously return the persistent instance of the given entity
class with the given identifier, or
null if there is no such
persistent instance. |
<T> io.smallrye.mutiny.Uni<T> |
find(Class<T> entityClass,
Object id,
org.hibernate.LockMode lockMode)
Asynchronously return the persistent instance of the given entity
class with the given identifier, requesting the given
LockMode . |
<T> io.smallrye.mutiny.Uni<T> |
find(EntityGraph<T> entityGraph,
Object id)
Asynchronously return the persistent instance with the given
identifier of an entity class, using the given
EntityGraph
as a fetch plan. |
io.smallrye.mutiny.Uni<Void> |
flush()
Force this session to flush asynchronously.
|
Integer |
getBatchSize()
The session-level batch size, or
null if it has not been
overridden. |
org.hibernate.CacheMode |
getCacheMode()
Get the current cache mode.
|
org.hibernate.Filter |
getEnabledFilter(String filterName)
Retrieve a currently enabled filter by name.
|
<T> EntityGraph<T> |
getEntityGraph(Class<T> rootType,
String graphName)
Obtain a named
EntityGraph |
org.hibernate.FlushMode |
getFlushMode()
Get the current flush mode for this session.
|
org.hibernate.LockMode |
getLockMode(Object entity)
Determine the current lock mode of the given entity.
|
<T> T |
getReference(Class<T> entityClass,
Object id)
Return the persistent instance of the given entity class with the
given identifier, assuming that the instance exists.
|
<T> T |
getReference(T entity)
Return the persistent instance with the same identity as the given
instance, which might be detached, assuming that the instance is
still persistent in the database.
|
<T> ResultSetMapping<T> |
getResultSetMapping(Class<T> resultType,
String mappingName)
Obtain a native SQL result set mapping defined via the annotation
SqlResultSetMapping . |
boolean |
isDefaultReadOnly() |
boolean |
isFetchProfileEnabled(String name)
Determine if the fetch profile with the given name is enabled for this
session.
|
boolean |
isOpen() |
boolean |
isReadOnly(Object entityOrProxy)
Is the specified entity or proxy read-only?
|
io.smallrye.mutiny.Uni<Void> |
lock(Object entity,
org.hibernate.LockMode lockMode)
Obtain the specified lock level upon the given object.
|
<T> io.smallrye.mutiny.Uni<T> |
merge(T entity)
Copy the state of the given object onto the persistent instance with
the same identifier.
|
<T> io.smallrye.mutiny.Uni<Void> |
mergeAll(T... entities)
Merge multiple entity instances at once.
|
io.smallrye.mutiny.Uni<Void> |
persist(Object entity)
Asynchronously persist the given transient instance, first assigning
a generated identifier.
|
io.smallrye.mutiny.Uni<Void> |
persistAll(Object... entities)
Persist multiple transient entity instances at once.
|
io.smallrye.mutiny.Uni<Void> |
refresh(Object entity)
Re-read the state of the given instance from the underlying database.
|
io.smallrye.mutiny.Uni<Void> |
refresh(Object entity,
org.hibernate.LockMode lockMode)
Re-read the state of the given instance from the underlying database,
requesting the given
LockMode . |
io.smallrye.mutiny.Uni<Void> |
refreshAll(Object... entities)
Refresh multiple entity instances at once.
|
io.smallrye.mutiny.Uni<Void> |
remove(Object entity)
Asynchronously remove a persistent instance from the datastore.
|
io.smallrye.mutiny.Uni<Void> |
removeAll(Object... entities)
Remove multiple entity instances at once.
|
Mutiny.Session |
setBatchSize(Integer batchSize)
Set the session-level batch size, overriding the batch size set
by the configuration property
hibernate.jdbc.batch_size . |
Mutiny.Session |
setCacheMode(org.hibernate.CacheMode cacheMode)
Set the
cache mode for this session. |
Mutiny.Session |
setDefaultReadOnly(boolean readOnly)
Change the default for entities and proxies loaded into this session
from modifiable to read-only mode, or from modifiable to read-only mode.
|
Mutiny.Session |
setFlushMode(org.hibernate.FlushMode flushMode)
Set the
flush mode for this session. |
Mutiny.Session |
setReadOnly(Object entityOrProxy,
boolean readOnly)
Set an unmodified persistent object to read-only mode, or a read-only
object to modifiable mode.
|
<T> io.smallrye.mutiny.Uni<T> |
unproxy(T association)
Asynchronously fetch an association that's configured for lazy loading,
and unwrap the underlying entity implementation from any proxy.
|
<T> io.smallrye.mutiny.Uni<T> |
withTransaction(Function<Mutiny.Transaction,io.smallrye.mutiny.Uni<T>> work)
Performs the given work within the scope of a database transaction,
automatically flushing the session.
|
close
<T> io.smallrye.mutiny.Uni<T> find(Class<T> entityClass, Object id)
null
if there is no such
persistent instance. If the instance is already associated with
the session, return the associated instance. This method never
returns an uninitialized instance.
session.find(Book.class, id).map(book -> print(book.getTitle()));
entityClass
- The entity typeid
- an identifierUni
EntityManager.find(Class, Object)
<T> io.smallrye.mutiny.Uni<T> find(Class<T> entityClass, Object id, org.hibernate.LockMode lockMode)
LockMode
.entityClass
- The entity typeid
- an identifierlockMode
- the requested LockMode
Uni
find(Class,Object)
,
this discussion of lock modes
<T> io.smallrye.mutiny.Uni<T> find(EntityGraph<T> entityGraph, Object id)
EntityGraph
as a fetch plan.entityGraph
- an EntityGraph
specifying the entity
and associations to be fetchedid
- an identifierfind(Class,Object)
<T> io.smallrye.mutiny.Uni<List<T>> find(Class<T> entityClass, Object... ids)
entityClass
- The entity typeids
- the identifiersUni
<T> io.smallrye.mutiny.Uni<T> find(Class<T> entityClass, Identifier<T> naturalId)
entityClass
- The entity typenaturalId
- the natural identifierUni
<T> T getReference(Class<T> entityClass, Object id)
fetch(Object)
.
You should not use this method to determine if an instance exists
(use find(java.lang.Class<T>, java.lang.Object)
instead). Use this only to retrieve an instance
which you safely assume exists, where non-existence would be an
actual error.
entityClass
- a persistent classid
- a valid identifier of an existing persistent instance of the classEntityManager.getReference(Class, Object)
<T> T getReference(T entity)
fetch(Object)
.entity
- a detached persistent instanceio.smallrye.mutiny.Uni<Void> persist(Object entity)
This operation cascades to associated instances if the association is
mapped with CascadeType.PERSIST
.
session.persist(newBook).map(v -> session.flush());
entity
- a transient instance of a persistent classEntityManager.persist(Object)
io.smallrye.mutiny.Uni<Void> persistAll(Object... entities)
persist(Object)
io.smallrye.mutiny.Uni<Void> remove(Object entity)
This operation cascades to associated instances if the association is
mapped with CascadeType.REMOVE
.
session.delete(book).thenAccept(v -> session.flush());
entity
- the managed persistent instance to be removedIllegalArgumentException
- if the given instance is not managedEntityManager.remove(Object)
io.smallrye.mutiny.Uni<Void> removeAll(Object... entities)
remove(Object)
<T> io.smallrye.mutiny.Uni<T> merge(T entity)
This operation cascades to associated instances if the association is
mapped with CascadeType.MERGE
.
entity
- a detached instance with state to be copiedEntityManager.merge(Object)
<T> io.smallrye.mutiny.Uni<Void> mergeAll(T... entities)
merge(Object)
io.smallrye.mutiny.Uni<Void> refresh(Object entity)
entity
- a managed persistent instanceIllegalArgumentException
- if the given instance is not managedEntityManager.refresh(Object)
io.smallrye.mutiny.Uni<Void> refresh(Object entity, org.hibernate.LockMode lockMode)
LockMode
.entity
- a managed persistent entity instancelockMode
- the requested lock moderefresh(Object)
io.smallrye.mutiny.Uni<Void> refreshAll(Object... entities)
refresh(Object)
io.smallrye.mutiny.Uni<Void> lock(Object entity, org.hibernate.LockMode lockMode)
LockMode.PESSIMISTIC_READ
,
LockMode.PESSIMISTIC_WRITE
,
LockMode.PESSIMISTIC_FORCE_INCREMENT
,
LockMode.OPTIMISTIC
, or
LockMode.OPTIMISTIC_FORCE_INCREMENT
.
CascadeType.LOCK
.entity
- a managed persistent instancelockMode
- the lock levelIllegalArgumentException
- if the given instance is not managedio.smallrye.mutiny.Uni<Void> flush()
session.flush().thenAccept(v -> print("done saving changes"));
EntityManager.flush()
<T> io.smallrye.mutiny.Uni<T> fetch(T association)
session.fetch(author.getBook()).thenAccept(book -> print(book.getTitle()));
association
- a lazy-loaded associationUni
Mutiny.fetch(Object)
,
Hibernate.initialize(Object)
<E,T> io.smallrye.mutiny.Uni<T> fetch(E entity, Attribute<E,T> field)
attribute metamodel
. Note that this feature is
only supported in conjunction with the Hibernate bytecode enhancer.
session.fetch(book, Book_.isbn).thenAccept(isbn -> print(isbn))
<T> io.smallrye.mutiny.Uni<T> unproxy(T association)
session.unproxy(author.getBook()).thenAccept(book -> print(book.getTitle()));
association
- a lazy-loaded associationUni
Hibernate.unproxy(Object)
org.hibernate.LockMode getLockMode(Object entity)
boolean contains(Object entity)
<R> Mutiny.Query<R> createQuery(String queryString)
Mutiny.Query
for the given HQL/JPQL query
string or HQL/JPQL update or delete statement. In the case of an
update or delete, the returned Mutiny.Query
must be executed using
Mutiny.Query.executeUpdate()
which returns an affected row count.queryString
- The HQL/JPQL query, update or delete statementMutiny.Query
instance for manipulation and executionEntityManager.createQuery(String)
<R> Mutiny.Query<R> createQuery(String queryString, Class<R> resultType)
Mutiny.Query
for the given HQL/JPQL query
string.queryString
- The HQL/JPQL queryresultType
- the Java type returned in each row of query resultsMutiny.Query
instance for manipulation and executionEntityManager.createQuery(String, Class)
<R> Mutiny.Query<R> createNamedQuery(String queryName)
Mutiny.Query
for the named query.queryName
- The name of the queryMutiny.Query
instance for manipulation and executionEntityManager.createQuery(String)
<R> Mutiny.Query<R> createNamedQuery(String queryName, Class<R> resultType)
Mutiny.Query
for the named query.queryName
- The name of the queryresultType
- the Java type returned in each row of query resultsMutiny.Query
instance for manipulation and executionEntityManager.createQuery(String, Class)
<R> Mutiny.Query<R> createNativeQuery(String queryString)
Mutiny.Query
for the given SQL query string,
or SQL update, insert, or delete statement. In the case of an update,
insert, or delete, the returned Mutiny.Query
must be executed using
Mutiny.Query.executeUpdate()
which returns an affected row count.
In the case of a query:
Object[]
.queryString
- The SQL select, update, insert, or delete statement<R> Mutiny.Query<R> createNativeQuery(String queryString, AffectedEntities affectedEntities)
Mutiny.Query
for the given SQL query string,
or SQL update, insert, or delete statement. In the case of an update,
insert, or delete, the returned Mutiny.Query
must be executed using
Mutiny.Query.executeUpdate()
which returns an affected row count.
In the case of a query:
Object[]
.affected entities
are synchronized with
the database before execution of the statement.queryString
- The SQL select, update, insert, or delete statementaffectedEntities
- The entities which are affected by the statement<R> Mutiny.Query<R> createNativeQuery(String queryString, Class<R> resultType)
Mutiny.Query
for the given SQL query
string, using the given resultType
to interpret the results.
Object
, or a built-in type
such as String
or Integer
, the result set must
have a single column, which will be returned as a scalar.
Object[]
, then the result set
must have multiple columns, which will be returned in arrays.
queryString
- The SQL queryresultType
- the Java type returned in each row of query resultsMutiny.Query
instance for manipulation and executionEntityManager.createNativeQuery(String, Class)
<R> Mutiny.Query<R> createNativeQuery(String queryString, Class<R> resultType, AffectedEntities affectedEntities)
Mutiny.Query
for the given SQL query
string, using the given resultType
to interpret the results.
Object
, or a built-in type
such as String
or Integer
, the result set must
have a single column, which will be returned as a scalar.
Object[]
, then the result set
must have multiple columns, which will be returned in arrays.
affected entities
are synchronized with
the database before execution of the query.queryString
- The SQL queryresultType
- the Java type returned in each row of query resultsaffectedEntities
- The entities which are affected by the queryMutiny.Query
instance for manipulation and executionEntityManager.createNativeQuery(String, Class)
<R> Mutiny.Query<R> createNativeQuery(String queryString, ResultSetMapping<R> resultSetMapping)
Mutiny.Query
for the given SQL query string,
using the given ResultSetMapping
to interpret the result set.queryString
- The SQL queryresultSetMapping
- the result set mappingMutiny.Query
instance for manipulation and executiongetResultSetMapping(Class, String)
,
EntityManager.createNativeQuery(String, String)
<R> Mutiny.Query<R> createNativeQuery(String queryString, ResultSetMapping<R> resultSetMapping, AffectedEntities affectedEntities)
Mutiny.Query
for the given SQL query string,
using the given ResultSetMapping
to interpret the result set.
Any affected entities
are synchronized with the
database before execution of the query.
queryString
- The SQL queryresultSetMapping
- the result set mappingaffectedEntities
- The entities which are affected by the queryMutiny.Query
instance for manipulation and executiongetResultSetMapping(Class, String)
,
EntityManager.createNativeQuery(String, String)
<R> Mutiny.Query<R> createQuery(CriteriaQuery<R> criteriaQuery)
Mutiny.Query
for the given criteria query.criteriaQuery
- The CriteriaQuery
Mutiny.Query
instance for manipulation and executionEntityManager.createQuery(String)
<R> Mutiny.Query<R> createQuery(CriteriaUpdate<R> criteriaUpdate)
Mutiny.Query
for the given criteria update.criteriaUpdate
- The CriteriaUpdate
Mutiny.Query
instance for manipulation and executionEntityManager.createQuery(String)
<R> Mutiny.Query<R> createQuery(CriteriaDelete<R> criteriaDelete)
Mutiny.Query
for the given criteria delete.criteriaDelete
- The CriteriaDelete
Mutiny.Query
instance for manipulation and executionEntityManager.createQuery(String)
Mutiny.Session setFlushMode(org.hibernate.FlushMode flushMode)
flush mode
for this session.
The flush mode determines the points at which the session is flushed. Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory.
For a logically "read only" session, it is reasonable to set the session's
flush mode to FlushMode.MANUAL
at the start of the session (in
order to achieve some extra performance).
flushMode
- the new flush modeorg.hibernate.FlushMode getFlushMode()
Mutiny.Session detach(Object entity)
This operation cascades to associated instances if the association is
mapped with CascadeType.DETACH
.
entity
- The entity to evictNullPointerException
- if the passed object is null
IllegalArgumentException
- if the passed object is not defined as an entityEntityManager.detach(Object)
Mutiny.Session clear()
EntityManager.clear()
Mutiny.Session enableFetchProfile(String name)
name
- The name of the fetch profile to be enabled.org.hibernate.UnknownProfileException
- Indicates that the given name does not
match any known profile namesfor discussion of this feature
<T> ResultSetMapping<T> getResultSetMapping(Class<T> resultType, String mappingName)
SqlResultSetMapping
.<T> EntityGraph<T> getEntityGraph(Class<T> rootType, String graphName)
EntityGraph
<T> EntityGraph<T> createEntityGraph(Class<T> rootType)
EntityGraph
<T> EntityGraph<T> createEntityGraph(Class<T> rootType, String graphName)
EntityGraph
Mutiny.Session disableFetchProfile(String name)
name
- The name of the fetch profile to be disabled.org.hibernate.UnknownProfileException
- Indicates that the given name does not
match any known profile namesfor discussion of this feature
boolean isFetchProfileEnabled(String name)
name
- The name of the profile to be checked.org.hibernate.UnknownProfileException
- Indicates that the given name does not
match any known profile namesfor discussion of this feature
Mutiny.Session setDefaultReadOnly(boolean readOnly)
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.
Session.setDefaultReadOnly(boolean)
boolean isDefaultReadOnly()
Mutiny.Session setReadOnly(Object entityOrProxy, boolean readOnly)
Session.setReadOnly(Object, boolean)
boolean isReadOnly(Object entityOrProxy)
Session.isReadOnly(Object)
Mutiny.Session setCacheMode(org.hibernate.CacheMode cacheMode)
cache mode
for this session.
The cache mode determines the manner in which this session interacts with the second level cache.
cacheMode
- The new cache mode.org.hibernate.CacheMode getCacheMode()
Mutiny.Session setBatchSize(Integer batchSize)
hibernate.jdbc.batch_size
.Integer getBatchSize()
null
if it has not been
overridden.org.hibernate.Filter enableFilter(String filterName)
filterName
- The name of the filter to be enabled.void disableFilter(String filterName)
filterName
- The name of the filter to be disabled.org.hibernate.Filter getEnabledFilter(String filterName)
filterName
- The name of the filter to be retrieved.<T> io.smallrye.mutiny.Uni<T> withTransaction(Function<Mutiny.Transaction,io.smallrye.mutiny.Uni<T>> work)
Mutiny.Transaction.markForRollback()
is called.
The resulting Mutiny.Transaction
object may also be obtained via
currentTransaction()
.
work
- a function which accepts Mutiny.Transaction
and returns
the result of the work as a Uni
.Mutiny.SessionFactory.withTransaction(BiFunction)
Mutiny.Transaction currentTransaction()
Mutiny.Transaction
, or null if no transaction
was started using withTransaction(Function)
.withTransaction(Function)
,
Mutiny.SessionFactory.withTransaction(BiFunction)
boolean isOpen()
Mutiny.Closeable.close()
has been calledCopyright © 2020-2022 Red Hat, Inc. All Rights Reserved.