Interface Mutiny.StatelessSession
- All Superinterfaces:
Mutiny.Closeable
- All Known Implementing Classes:
MutinyStatelessSessionImpl
- Enclosing interface:
- Mutiny
StatelessSession
interface, which provides a
command-oriented API for performing bulk operations against a database.
A stateless session does not implement a first-level cache nor interact with any second-level cache, nor does it implement transactional write-behind or automatic dirty checking, nor do operations cascade to associated instances. Changes to many to many associations and element collections may not be made persistent in a stateless session. Operations performed via a stateless session bypass Hibernate's event model and interceptors.
For certain kinds of work, a stateless session may perform slightly better than a stateful session.
In particular, for a session which loads many entities, use of a
StatelessSession
alleviates the need to call:
Mutiny.Session.clear()
orMutiny.Session.detach(Object)
to perform first-level cache management, andMutiny.Session.setCacheMode(CacheMode)
to bypass interaction with the second-level cache.
Stateless sessions are vulnerable to data aliasing effects, due to the lack of a first-level cache.
- See Also:
-
StatelessSession
-
Method Summary
Modifier and TypeMethodDescriptionio.smallrye.mutiny.Uni<Void>
close()
Close the reactive session and release the underlying database connection.<T> jakarta.persistence.EntityGraph<T>
createEntityGraph
(Class<T> rootType) Create a new mutableEntityGraph
<T> jakarta.persistence.EntityGraph<T>
createEntityGraph
(Class<T> rootType, String graphName) Create a new mutable copy of a namedEntityGraph
createMutationQuery
(String queryString) Create an instance ofMutiny.MutationQuery
for the given HQL/JPQL update or delete statement.<R> Mutiny.Query<R>
createNamedQuery
(String queryName) Create an instance ofMutiny.Query
for the named query.<R> Mutiny.SelectionQuery<R>
createNamedQuery
(String queryName, Class<R> resultType) Create an instance ofMutiny.SelectionQuery
for the named query.<R> Mutiny.Query<R>
createNativeQuery
(String queryString) Create an instance ofMutiny.Query
for the given SQL query string, or SQL update, insert, or delete statement.<R> Mutiny.SelectionQuery<R>
createNativeQuery
(String queryString, Class<R> resultType) Create an instance ofMutiny.SelectionQuery
for the given SQL query string, using the givenresultType
to interpret the results.<R> Mutiny.SelectionQuery<R>
createNativeQuery
(String queryString, ResultSetMapping<R> resultSetMapping) Create an instance ofMutiny.SelectionQuery
for the given SQL query string, using the givenResultSetMapping
to interpret the result set.<R> Mutiny.SelectionQuery<R>
createQuery
(jakarta.persistence.criteria.CriteriaQuery<R> criteriaQuery) Create an instance ofMutiny.SelectionQuery
for the given criteria query.<R> Mutiny.Query<R>
createQuery
(String queryString) Deprecated.<R> Mutiny.SelectionQuery<R>
createQuery
(String queryString, Class<R> resultType) Create an instance ofMutiny.SelectionQuery
for the given HQL/JPQL query string and query result type.<R> Mutiny.SelectionQuery<R>
createSelectionQuery
(String queryString, Class<R> resultType) Create an instance ofMutiny.SelectionQuery
for the given HQL/JPQL query string.Obtain the transaction currently associated with this session, if any.io.smallrye.mutiny.Uni<Void>
Delete a row.io.smallrye.mutiny.Uni<Void>
Delete multiple rows.io.smallrye.mutiny.Uni<Void>
Delete multiple rows.<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>
Retrieve a row, using the givenEntityGraph
as a fetch plan.<T> io.smallrye.mutiny.Uni<T>
Retrieve a row.default <T> io.smallrye.mutiny.Uni<T>
Retrieve a row, obtaining the specified lock mode.<T> io.smallrye.mutiny.Uni<T>
Retrieve a row, obtaining the specified lock mode.<T> jakarta.persistence.EntityGraph<T>
getEntityGraph
(Class<T> rootType, String graphName) Obtain a namedEntityGraph
TheMutiny.SessionFactory
which created this session.<T> ResultSetMapping<T>
getResultSetMapping
(Class<T> resultType, String mappingName) Obtain a native SQL result set mapping defined via the annotationSqlResultSetMapping
.io.smallrye.mutiny.Uni<Void>
Insert a row.io.smallrye.mutiny.Uni<Void>
Insert multiple rows using the specified batch size.io.smallrye.mutiny.Uni<Void>
Insert multiple rows.boolean
isOpen()
io.smallrye.mutiny.Uni<Void>
Refresh the entity instance state from the database.default io.smallrye.mutiny.Uni<Void>
Refresh the entity instance state from the database.io.smallrye.mutiny.Uni<Void>
Refresh the entity instance state from the database.io.smallrye.mutiny.Uni<Void>
refreshAll
(int batchSize, Object... entities) Refresh the entity instance state from the database using the selected batch size.io.smallrye.mutiny.Uni<Void>
refreshAll
(Object... entities) Refresh the entity instance state from the database.io.smallrye.mutiny.Uni<Void>
Update a row.io.smallrye.mutiny.Uni<Void>
Update multiple rows.io.smallrye.mutiny.Uni<Void>
Update multiple rows.io.smallrye.mutiny.Uni<Void>
Use a SQLmerge into
statement to perform an upsert.io.smallrye.mutiny.Uni<Void>
Use a SQLmerge into
statement to perform an upsert.<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.
-
Method Details
-
get
Retrieve a row.- Parameters:
entityClass
- The class of the entity to retrieveid
- The id of the entity to retrieve- Returns:
- a detached entity instance, via a
Uni
- See Also:
-
StatelessSession.get(Class, Object)
-
get
Retrieve a row, obtaining the specified lock mode.- Parameters:
entityClass
- The class of the entity to retrieveid
- The id of the entity to retrievelockMode
- The lock mode to apply to the entity- Returns:
- a detached entity instance, via a
Uni
- See Also:
-
StatelessSession.get(Class, Object, LockMode)
-
get
default <T> io.smallrye.mutiny.Uni<T> get(Class<T> entityClass, Object id, jakarta.persistence.LockModeType lockModeType) Retrieve a row, obtaining the specified lock mode.- Parameters:
entityClass
- The class of the entity to retrieveid
- The id of the entity to retrievelockModeType
- The lock mode to apply to the entity- Returns:
- a detached entity instance, via a
Uni
- See Also:
-
StatelessSession.get(Class, Object, LockMode)
-
get
Retrieve a row, using the givenEntityGraph
as a fetch plan.- Parameters:
entityGraph
- anEntityGraph
specifying the entity and associations to be fetchedid
- The id of the entity to retrieve- Returns:
- a detached entity instance, via a
Uni
-
createQuery
Deprecated.See explanation inQueryProducer.createSelectionQuery(String)
Create an instance ofMutiny.Query
for the given HQL/JPQL query string or HQL/JPQL update or delete statement. In the case of an update or delete, the returnedMutiny.Query
must be executed usingMutiny.MutationQuery.executeUpdate()
which returns an affected row count.- Parameters:
queryString
- The HQL/JPQL query, update or delete statement- Returns:
- The
Mutiny.Query
instance for manipulation and execution - See Also:
-
createQuery
Create an instance ofMutiny.SelectionQuery
for the given HQL/JPQL query string and query result type.- Parameters:
queryString
- The HQL/JPQL queryresultType
- the Java type returned in each row of query results- Returns:
- The
Mutiny.Query
instance for manipulation and execution - See Also:
-
createSelectionQuery
Create an instance ofMutiny.SelectionQuery
for the given HQL/JPQL query string.- Parameters:
queryString
- The HQL/JPQL query- Returns:
- The
Mutiny.SelectionQuery
instance for manipulation and execution - See Also:
-
EntityManager.createQuery(String, Class)
-
createMutationQuery
Create an instance ofMutiny.MutationQuery
for the given HQL/JPQL update or delete statement.- Parameters:
queryString
- The HQL/JPQL query, update or delete statement- Returns:
- The
Mutiny.MutationQuery
instance for manipulation and execution - See Also:
-
EntityManager.createQuery(String)
-
createNamedQuery
Create an instance ofMutiny.Query
for the named query.- Parameters:
queryName
- The name of the query- Returns:
- The
Mutiny.Query
instance for manipulation and execution - See Also:
-
EntityManager.createQuery(String)
-
createNamedQuery
Create an instance ofMutiny.SelectionQuery
for the named query.- Parameters:
queryName
- The name of the queryresultType
- the Java type returned in each row of query results- Returns:
- The
Mutiny.SelectionQuery
instance for manipulation and execution - See Also:
-
EntityManager.createQuery(String, Class)
-
createNativeQuery
Create an instance ofMutiny.Query
for the given SQL query string, or SQL update, insert, or delete statement. In the case of an update, insert, or delete, the returnedMutiny.Query
must be executed usingMutiny.MutationQuery.executeUpdate()
which returns an affected row count.- Parameters:
queryString
- The SQL select, update, insert, or delete statement- See Also:
-
createNativeQuery
Create an instance ofMutiny.SelectionQuery
for the given SQL query string, using the givenresultType
to interpret the results.- Parameters:
queryString
- The SQL queryresultType
- the Java type returned in each row of query results- Returns:
- The
Mutiny.Query
instance for manipulation and execution - See Also:
-
createNativeQuery
<R> Mutiny.SelectionQuery<R> createNativeQuery(String queryString, ResultSetMapping<R> resultSetMapping) Create an instance ofMutiny.SelectionQuery
for the given SQL query string, using the givenResultSetMapping
to interpret the result set.- Parameters:
queryString
- The SQL queryresultSetMapping
- the result set mapping- Returns:
- The
Mutiny.Query
instance for manipulation and execution - See Also:
-
createQuery
<R> Mutiny.SelectionQuery<R> createQuery(jakarta.persistence.criteria.CriteriaQuery<R> criteriaQuery) Create an instance ofMutiny.SelectionQuery
for the given criteria query.- Parameters:
criteriaQuery
- TheCriteriaQuery
- Returns:
- The
Mutiny.SelectionQuery
instance for manipulation and execution - See Also:
-
EntityManager.createQuery(String)
-
insert
Insert a row.- Parameters:
entity
- a new transient instance- See Also:
-
StatelessSession.insert(Object)
-
insertAll
Insert multiple rows.- Parameters:
entities
- new transient instances- See Also:
-
StatelessSession.insert(Object)
-
insertAll
Insert multiple rows using the specified batch size.- Parameters:
batchSize
- the batch sizeentities
- new transient instances- See Also:
-
StatelessSession.insert(Object)
-
delete
Delete a row.- Parameters:
entity
- a detached entity instance- See Also:
-
StatelessSession.delete(Object)
-
deleteAll
Delete multiple rows.- Parameters:
entities
- detached entity instances- See Also:
-
StatelessSession.delete(Object)
-
deleteAll
Delete multiple rows.- Parameters:
batchSize
- the batch sizeentities
- detached entity instances- See Also:
-
StatelessSession.delete(Object)
-
update
Update a row.- Parameters:
entity
- a detached entity instance- See Also:
-
StatelessSession.update(Object)
-
updateAll
Update multiple rows.- Parameters:
entities
- detached entity instances- See Also:
-
StatelessSession.update(Object)
-
updateAll
Update multiple rows.- Parameters:
batchSize
- the batch sizeentities
- detached entity instances- See Also:
-
StatelessSession.update(Object)
-
refresh
Refresh the entity instance state from the database.- Parameters:
entity
- The entity to be refreshed.- See Also:
-
StatelessSession.refresh(Object)
-
upsert
Use a SQLmerge into
statement to perform an upsert.- Parameters:
entity
- a detached entity instance- See Also:
-
StatelessSession.upsert(Object)
-
upsert
Use a SQLmerge into
statement to perform an upsert.- Parameters:
entityName
- The entityName for the entity to be mergedentity
- a detached entity instance- Throws:
org.hibernate.TransientObjectException
- is the entity is transient- See Also:
-
StatelessSession.upsert(String, Object)
-
refreshAll
Refresh the entity instance state from the database.- Parameters:
entities
- The entities to be refreshed.- See Also:
-
StatelessSession.refresh(Object)
-
refreshAll
Refresh the entity instance state from the database using the selected batch size.- Parameters:
batchSize
- the batch sizeentities
- The entities to be refreshed.- See Also:
-
StatelessSession.refresh(Object)
-
refresh
Refresh the entity instance state from the database.- Parameters:
entity
- The entity to be refreshed.lockMode
- The LockMode to be applied.- See Also:
-
StatelessSession.refresh(Object, LockMode)
-
refresh
default io.smallrye.mutiny.Uni<Void> refresh(Object entity, jakarta.persistence.LockModeType lockModeType) Refresh the entity instance state from the database.- Parameters:
entity
- The entity to be refreshed.lockModeType
- The LockMode to be applied.- See Also:
-
StatelessSession.refresh(Object, LockMode)
-
fetch
<T> io.smallrye.mutiny.Uni<T> fetch(T association) Asynchronously fetch an association that's configured for lazy loading.session.fetch(author.getBook()).thenAccept(book -> print(book.getTitle()))
Warning: this operation in a stateless session is quite sensitive to data aliasing effects and should be used with great care.
- Parameters:
association
- a lazy-loaded association- Returns:
- the fetched association, via a
Uni
- See Also:
-
Hibernate.initialize(Object)
-
getResultSetMapping
Obtain a native SQL result set mapping defined via the annotationSqlResultSetMapping
. -
getEntityGraph
Obtain a namedEntityGraph
-
createEntityGraph
Create a new mutableEntityGraph
-
createEntityGraph
Create a new mutable copy of a namedEntityGraph
-
withTransaction
<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. The transaction will be rolled back if the work completes with an uncaught exception, or ifMutiny.Transaction.markForRollback()
is called.- If there is already a transaction associated with this session, the work is executed in the context of the existing transaction, and no new transaction is initiated.
- If there is no transaction associated with this session, a new transaction is started, and the work is executed in the context of the new transaction.
- Parameters:
work
- a function which acceptsMutiny.Transaction
and returns the result of the work as aUni
.- See Also:
-
currentTransaction
Mutiny.Transaction currentTransaction()Obtain the transaction currently associated with this session, if any.- Returns:
- the
Mutiny.Transaction
, or null if no transaction was started usingwithTransaction(Function)
. - See Also:
-
isOpen
boolean isOpen()- Returns:
- false if
close()
has been called
-
close
io.smallrye.mutiny.Uni<Void> close()Close the reactive session and release the underlying database connection.- Specified by:
close
in interfaceMutiny.Closeable
-
getFactory
Mutiny.SessionFactory getFactory()TheMutiny.SessionFactory
which created this session.
-
QueryProducer.createSelectionQuery(String)