Interface Stage.SessionFactory
- All Superinterfaces:
AutoCloseable
- Enclosing interface:
- Stage
reactive sessions
.
A Stage.SessionFactory
may be obtained from an instance of
EntityManagerFactory
as follows:
Stage.SessionFactory sessionFactory = createEntityManagerFactory("example") .unwrap(Stage.SessionFactory.class);Here, configuration properties must be specified in
persistence.xml
.
Alternatively, a Stage.SessionFactory
may be obtained via
programmatic configuration of Hibernate using:
Configuration configuration = new Configuration(); ... Stage.SessionFactory sessionFactory = configuration.buildSessionFactory( new ReactiveServiceRegistryBuilder() .applySettings( configuration.getProperties() ) .build() ) .unwrap(Stage.SessionFactory.class);
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Destroy the session factory and clean up its connection pool.getCache()
Obtain theCache
object for managing the second-level cache.jakarta.persistence.criteria.CriteriaBuilder
jakarta.persistence.metamodel.Metamodel
Obtain the JPAMetamodel
for the persistence unit.Obtain theStatistics
object exposing factory-level metrics.boolean
isOpen()
Obtain a newreactive session
CompletionStage
, the main interaction point between the user's program and Hibernate Reactive.openSession
(String tenantId) Obtain a newreactive session
CompletionStage
for a specified tenant.Obtain areactive stateless session
CompletionStage
.openStatelessSession
(String tenantId) Obtain areactive stateless session
CompletionStage
.<T> CompletionStage<T>
withSession
(String tenantId, Function<Stage.Session, CompletionStage<T>> work) Perform work using areactive session
for a specified tenant.<T> CompletionStage<T>
withSession
(Function<Stage.Session, CompletionStage<T>> work) Perform work using areactive session
.<T> CompletionStage<T>
withStatelessSession
(String tenantId, Function<Stage.StatelessSession, CompletionStage<T>> work) Perform work using astateless session
.<T> CompletionStage<T>
Perform work using astateless session
.<T> CompletionStage<T>
withStatelessTransaction
(String tenantId, BiFunction<Stage.StatelessSession, Stage.Transaction, CompletionStage<T>> work) Perform work using areactive session
within an associatedtransaction
.<T> CompletionStage<T>
withStatelessTransaction
(BiFunction<Stage.StatelessSession, Stage.Transaction, CompletionStage<T>> work) Perform work using areactive session
within an associatedtransaction
.default <T> CompletionStage<T>
Perform work using areactive session
within an associatedtransaction
.<T> CompletionStage<T>
withTransaction
(String tenantId, BiFunction<Stage.Session, Stage.Transaction, CompletionStage<T>> work) Perform work using areactive session
for a specified tenant within an associatedtransaction
.<T> CompletionStage<T>
Perform work using areactive session
within an associatedtransaction
.default <T> CompletionStage<T>
withTransaction
(Function<Stage.Session, CompletionStage<T>> work) Perform work using areactive session
within an associated transaction.
-
Method Details
-
openSession
CompletionStage<Stage.Session> openSession()Obtain a newreactive session
CompletionStage
, the main interaction point between the user's program and Hibernate Reactive.When the
CompletionStage
completes successfully it returns a newly created session.The client must explicitly close the session by calling
Stage.Closeable.close()
.- See Also:
-
openSession
Obtain a newreactive session
CompletionStage
for a specified tenant.When the
CompletionStage
completes successfully it returns a newly created session.The client must explicitly close the session by calling
Stage.Closeable.close()
.- Parameters:
tenantId
- the id of the tenant- See Also:
-
openStatelessSession
CompletionStage<Stage.StatelessSession> openStatelessSession()Obtain areactive stateless session
CompletionStage
.When the
CompletionStage
completes successfully it returns a newly created session.The client must explicitly close the session by calling
Stage.StatelessSession.close()
. -
openStatelessSession
Obtain areactive stateless session
CompletionStage
.When the
CompletionStage
completes successfully it returns a newly created session.The client must explicitly close the session by calling
Stage.StatelessSession.close()
.- Parameters:
tenantId
- the id of the tenant
-
withSession
Perform work using areactive session
.- If there is already a session associated with the current reactive stream, then the work will be executed using that session.
- Otherwise, if there is no session associated with the current stream, a new session will be created.
The session will be closed automatically, but must be flushed explicitly if necessary.
- Parameters:
work
- a function which accepts the session and returns the result of the work as aCompletionStage
.
-
withSession
<T> CompletionStage<T> withSession(String tenantId, Function<Stage.Session, CompletionStage<T>> work) Perform work using areactive session
for a specified tenant.- If there is already a session associated with the current reactive stream, and the given tenant, then the work will be executed using that session.
- Otherwise, a new session will be created.
The session will be closed automatically, but must be flushed explicitly if necessary.
- Parameters:
tenantId
- the id of the tenantwork
- a function which accepts the session and returns the result of the work as aCompletionStage
.
-
withTransaction
<T> CompletionStage<T> withTransaction(BiFunction<Stage.Session, Stage.Transaction, CompletionStage<T>> work) Perform work using areactive session
within an associatedtransaction
.- If there is already a stateless session associated with the current reactive stream, then the work will be executed using that session.
- Otherwise, if there is no stateless session associated with the current stream, a new stateless session will be created.
The session will be
flushed
and closed automatically, and the transaction committed automatically.- Parameters:
work
- a function which accepts the session and transaction and returns the result of the work as aCompletionStage
.- See Also:
-
withTransaction
Perform work using areactive session
within an associated transaction.- If there is already a session associated with the current reactive stream, then the work will be executed using that session.
- Otherwise, if there is no stateless session associated with the current stream, a new stateless session will be created.
The session will be
flushed
and closed automatically, and the transaction committed automatically.- Parameters:
work
- a function which accepts the session and returns the result of the work as aCompletionStage
.- See Also:
-
withTransaction
<T> CompletionStage<T> withTransaction(String tenantId, BiFunction<Stage.Session, Stage.Transaction, CompletionStage<T>> work) Perform work using areactive session
for a specified tenant within an associatedtransaction
.- If there is already a session associated with the current reactive stream and the given tenant, then the work will be executed using that session.
- Otherwise, if there is no stateless session associated with the current stream and the given tenant, a new stateless session will be created.
The session will be
flushed
and closed automatically, and the transaction committed automatically.- Parameters:
tenantId
- the id of the tenantwork
- a function which accepts the session and returns the result of the work as aCompletionStage
.- See Also:
-
withStatelessTransaction
default <T> CompletionStage<T> withStatelessTransaction(Function<Stage.StatelessSession, CompletionStage<T>> work) Perform work using areactive session
within an associatedtransaction
.- If there is already a stateless session associated with the current reactive stream, then the work will be executed using that session.
- Otherwise, if there is no stateless session associated with the current stream, a new stateless session will be created.
The session will be closed automatically, and the transaction committed automatically.
- Parameters:
work
- a function which accepts the stateless session and returns the result of the work as aCompletionStage
.- See Also:
-
withStatelessTransaction
<T> CompletionStage<T> withStatelessTransaction(BiFunction<Stage.StatelessSession, Stage.Transaction, CompletionStage<T>> work) Perform work using areactive session
within an associatedtransaction
.- If there is already a stateless session associated with the current reactive stream, then the work will be executed using that session.
- Otherwise, if there is no stateless session associated with the current stream, a new stateless session will be created.
The session will be closed automatically, and the transaction committed automatically.
- Parameters:
work
- a function which accepts the stateless session and returns the result of the work as aCompletionStage
.- See Also:
-
withStatelessTransaction
<T> CompletionStage<T> withStatelessTransaction(String tenantId, BiFunction<Stage.StatelessSession, Stage.Transaction, CompletionStage<T>> work) Perform work using areactive session
within an associatedtransaction
.- If there is already a stateless session associated with the current reactive stream and the given tenant, then the work will be executed using that session.
- Otherwise, if there is no stateless session associated with the current stream, a new stateless session will be created.
The session will be closed automatically, and the transaction committed automatically.
- Parameters:
tenantId
- the id of the tenantwork
- a function which accepts the stateless session and returns the result of the work as aCompletionStage
.- See Also:
-
withStatelessSession
<T> CompletionStage<T> withStatelessSession(Function<Stage.StatelessSession, CompletionStage<T>> work) Perform work using astateless session
.- If there is already a stateless session associated with the current reactive stream, then the work will be executed using that session.
- Otherwise, if there is no stateless session associated with the current stream, a new stateless session will be created.
The session will be closed automatically.
- Parameters:
work
- a function which accepts the session and returns the result of the work as aCompletionStage
.
-
withStatelessSession
<T> CompletionStage<T> withStatelessSession(String tenantId, Function<Stage.StatelessSession, CompletionStage<T>> work) Perform work using astateless session
.- If there is already a stateless session associated with the current reactive stream, then the work will be executed using that session.
- Otherwise, if there is no stateless session associated with the current stream, a new stateless session will be created.
The session will be closed automatically.
- Parameters:
tenantId
- the id of the tenantwork
- a function which accepts the session and returns the result of the work as aCompletionStage
.
-
getCriteriaBuilder
jakarta.persistence.criteria.CriteriaBuilder getCriteriaBuilder()- Returns:
- an instance of
CriteriaBuilder
for creating criteria queries.
-
getMetamodel
jakarta.persistence.metamodel.Metamodel getMetamodel()Obtain the JPAMetamodel
for the persistence unit. -
getCache
Cache getCache()Obtain theCache
object for managing the second-level cache. -
getStatistics
Statistics getStatistics()Obtain theStatistics
object exposing factory-level metrics. -
close
void close()Destroy the session factory and clean up its connection pool.- Specified by:
close
in interfaceAutoCloseable
-
isOpen
boolean isOpen()- Returns:
- false if
close()
has been called
-