Interface Mutiny.StatelessSession
- All Superinterfaces:
Mutiny.Closeable
,Mutiny.QueryProducer
- All Known Implementing Classes:
MutinyStatelessSessionDelegator
- 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:
-
Method Summary
Modifier and TypeMethodDescriptionio.smallrye.mutiny.Uni<Void>
close()
Close the reactive session and release the underlying database connection.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, using the number of the given entities as the batch size.io.smallrye.mutiny.Uni<Void>
deleteMultiple
(List<?> entities) Delete multiple rows, using the size of the given list as the batch size.<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.<T> io.smallrye.mutiny.Uni<List<T>>
Retrieve multiple rows.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.TheMutiny.SessionFactory
which created this session.getIdentifier
(Object entity) Return the identifier value of the given entity, which may be detached.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, using the number of the given entities as the batch size.io.smallrye.mutiny.Uni<Void>
insertMultiple
(List<?> entities) Insert multiple rows, using the size of the given list as the batch size.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, using the number of the given entities as the batch size.io.smallrye.mutiny.Uni<Void>
refreshMultiple
(List<?> entities) Refresh the entity instance state from the database using the size of the given list as the batch size.io.smallrye.mutiny.Uni<Void>
Update a row.io.smallrye.mutiny.Uni<Void>
Update multiple rows.io.smallrye.mutiny.Uni<Void>
Update multiple rows, using the number of the given entities as the batch size.io.smallrye.mutiny.Uni<Void>
updateMultiple
(List<?> entities) Update multiple rows, using the size of the given list as the batch size.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 on multiple rows using the specified batch size.io.smallrye.mutiny.Uni<Void>
Use a SQLmerge into
statement to perform an upsert on multiple rows using the size of the given array as batch size.io.smallrye.mutiny.Uni<Void>
upsertMultiple
(List<?> entities) Use a SQLmerge into
statement to perform an upsert on multiple rows using the size of the given list as batch size.<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.Methods inherited from interface org.hibernate.reactive.mutiny.Mutiny.QueryProducer
createEntityGraph, createEntityGraph, createMutationQuery, createMutationQuery, createMutationQuery, createMutationQuery, createNamedQuery, createNamedQuery, createNativeQuery, createNativeQuery, createNativeQuery, createNativeQuery, createNativeQuery, createNativeQuery, createQuery, createQuery, createQuery, createQuery, createQuery, createQuery, createSelectionQuery, getCriteriaBuilder, getEntityGraph, getResultSetMapping
-
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:
-
get
Retrieve multiple rows.- Parameters:
entityClass
- The class of the entity to retrieveids
- The ids of the entities to retrieve- Returns:
- a list of detached entity instances, via a
Uni
- See Also:
-
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:
-
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:
-
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
-
insert
Insert a row.- Parameters:
entity
- a new transient instance- See Also:
-
insertAll
Insert multiple rows, using the number of the given entities as the batch size.- Parameters:
entities
- new transient instances- See Also:
-
insertAll
Insert multiple rows using the specified batch size.- Parameters:
batchSize
- the batch sizeentities
- new transient instances- See Also:
-
insertMultiple
Insert multiple rows, using the size of the given list as the batch size.- Parameters:
entities
- new transient instances- See Also:
-
delete
Delete a row.- Parameters:
entity
- a detached entity instance- See Also:
-
deleteAll
Delete multiple rows, using the number of the given entities as the batch size.- Parameters:
entities
- detached entity instances- See Also:
-
deleteAll
Delete multiple rows.- Parameters:
batchSize
- the batch sizeentities
- detached entity instances- See Also:
-
deleteMultiple
Delete multiple rows, using the size of the given list as the batch size.- Parameters:
entities
- detached entity instances- See Also:
-
update
Update a row.- Parameters:
entity
- a detached entity instance- See Also:
-
updateAll
Update multiple rows, using the number of the given entities as the batch size.- Parameters:
entities
- detached entity instances- See Also:
-
updateAll
Update multiple rows.- Parameters:
batchSize
- the batch sizeentities
- detached entity instances- See Also:
-
updateMultiple
Update multiple rows, using the size of the given list as the batch size.- Parameters:
entities
- detached entity instances- See Also:
-
upsert
Use a SQLmerge into
statement to perform an upsert.- Parameters:
entity
- a detached entity instance- See Also:
-
upsertAll
Use a SQLmerge into
statement to perform an upsert on multiple rows using the size of the given array as batch size.- Parameters:
entities
- the entities to upsert- See Also:
-
upsertAll
Use a SQLmerge into
statement to perform an upsert on multiple rows using the specified batch size.- Parameters:
batchSize
- the batch sizeentities
- the list of entities to upsert- See Also:
-
upsertMultiple
Use a SQLmerge into
statement to perform an upsert on multiple rows using the size of the given list as batch size.- Parameters:
entities
- the entities to upsert- See Also:
-
refresh
Refresh the entity instance state from the database.- Parameters:
entity
- The entity to be refreshed.- See Also:
-
refreshAll
Refresh the entity instance state from the database, using the number of the given entities as the batch size.- Parameters:
entities
- The entities to be refreshed.- See Also:
-
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:
-
refreshMultiple
Refresh the entity instance state from the database using the size of the given list as the batch size.- Parameters:
entities
- The entities to be refreshed.- See Also:
-
refresh
Refresh the entity instance state from the database.- Parameters:
entity
- The entity to be refreshed.lockMode
- The LockMode to be applied.- See Also:
-
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:
-
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:
-
getIdentifier
Return the identifier value of the given entity, which may be detached.- Parameters:
entity
- a persistent instance associated with this session- Returns:
- the identifier
- Since:
- 3.0
-
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.
-