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 TypeMethodDescriptionvoidclose()Destroy the session factory and clean up its connection pool.getCache()Obtain theCacheobject for managing the second-level cache.Return the current instance ofStage.Session, if any.Return the current instance ofStage.Session, if any.jakarta.persistence.metamodel.MetamodelObtain the JPAMetamodelfor the persistence unit.Obtain theStatisticsobject exposing factory-level metrics.booleanisOpen()Obtain a new reactive sessionCompletionStage, the main interaction point between the user's program and Hibernate Reactive.openSession(String tenantId) Obtain a new reactive sessionCompletionStagefor a specified tenant.Obtain areactive stateless sessionCompletionStage.openStatelessSession(String tenantId) Obtain areactive stateless sessionCompletionStage.<T> CompletionStage<T>withSession(String tenantId, Function<Stage.Session, CompletionStage<T>> work) Perform work using a reactive session for a specified tenant.<T> CompletionStage<T>withSession(Function<Stage.Session, CompletionStage<T>> work) Perform work using a reactive session.<T> CompletionStage<T>withStatelessSession(String tenantId, Function<Stage.StatelessSession, CompletionStage<T>> work) Perform work using a stateless session.<T> CompletionStage<T>Perform work using a stateless session.<T> CompletionStage<T>withStatelessTransaction(String tenantId, BiFunction<Stage.StatelessSession, Stage.Transaction, CompletionStage<T>> work) Perform work using a reactive session for the tenant with the specified tenant id within an associatedtransaction.<T> CompletionStage<T>withStatelessTransaction(BiFunction<Stage.StatelessSession, Stage.Transaction, CompletionStage<T>> work) Perform work using a reactive session within an associatedtransaction.default <T> CompletionStage<T>Perform work using a reactive session within an associatedtransaction.<T> CompletionStage<T>withTransaction(String tenantId, BiFunction<Stage.Session, Stage.Transaction, CompletionStage<T>> work) Perform work using a reactive session for the tenant with the specified tenant id within an associatedtransaction.<T> CompletionStage<T>Perform work using a reactive session within an associatedtransaction.default <T> CompletionStage<T>withTransaction(Function<Stage.Session, CompletionStage<T>> work) Perform work using a reactive session within an associated transaction.
-
Method Details
-
openSession
CompletionStage<Stage.Session> openSession()Obtain a new reactive sessionCompletionStage, the main interaction point between the user's program and Hibernate Reactive.When the
CompletionStagecompletes successfully it returns a newly created session.The client must explicitly close the session by calling
Stage.Closeable.close().- See Also:
-
openSession
Obtain a new reactive sessionCompletionStagefor a specified tenant.When the
CompletionStagecompletes 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 sessionCompletionStage.When the
CompletionStagecompletes successfully it returns a newly created session.The client must explicitly close the session by calling
Stage.StatelessSession.close(). -
openStatelessSession
Obtain areactive stateless sessionCompletionStage.When the
CompletionStagecompletes 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 a reactive 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 a reactive 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 a reactive 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
flushedand 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 a reactive 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
flushedand 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 a reactive session for the tenant with the specified tenant id within an associatedtransaction.- If there is already a session associated with the current reactive stream and given tenant id, then the work will be executed using that session.
- Otherwise, if there is no stateless session associated with the current stream and given tenant id, a new stateless session will be created.
The session will be
flushedand 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 a reactive 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 a reactive 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 a reactive session for the tenant with the specified tenant id within an associatedtransaction.- If there is already a stateless session associated with the current reactive stream and given tenant id, then the work will be executed using that session.
- Otherwise, if there is no stateless session associated with the current stream and given tenant id, 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 a stateless 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 a stateless 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
HibernateCriteriaBuilder getCriteriaBuilder()- Returns:
- an instance of
CriteriaBuilderfor creating criteria queries.
-
getMetamodel
jakarta.persistence.metamodel.Metamodel getMetamodel()Obtain the JPAMetamodelfor the persistence unit. -
getCache
Cache getCache()Obtain theCacheobject for managing the second-level cache. -
getStatistics
Statistics getStatistics()Obtain theStatisticsobject exposing factory-level metrics. -
getCurrentSession
Stage.Session getCurrentSession()Return the current instance ofStage.Session, if any. A current session exists only when this method is called from within an invocation ofwithSession(Function)orwithTransaction(Function).- Returns:
- the current instance, if any, or
null - Since:
- 3.0
-
getCurrentStatelessSession
Stage.StatelessSession getCurrentStatelessSession()Return the current instance ofStage.Session, if any. A current session exists only when this method is called from within an invocation ofwithStatelessSession(Function)orwithStatelessTransaction(Function).- Returns:
- the current instance, if any, or
null - Since:
- 3.0
-
close
void close()Destroy the session factory and clean up its connection pool.- Specified by:
closein interfaceAutoCloseable
-
isOpen
boolean isOpen()- Returns:
- false if
close()has been called
-