java.lang.Object
io.jooby.hibernate.TransactionalRequest
- All Implemented Interfaces:
Route.Aware
,Route.Filter
Attaches a
Session
and EntityManager
to the current request
via SessionRequest
.
The route pipeline runs inside a transaction which is commit on success or rollback in case of exception.
Applies the SessionRequest
decorator, so there is no need to use session request in
addition to transactional request.
Usage:
{
install(new HikariModule());
install(new HibernateModule());
use(new TransactionalRequest());
get("/handle", ctx -> {
EntityManager handle = require(EntityManager.class);
// work with handle.
});
}
- Since:
- 2.0.0
- Author:
- edgar
-
Constructor Summary
ConstructorDescriptionCreates a new transactional request and attach to the default/first session factory registered.TransactionalRequest
(String name) Creates a new transactional request and attach the to a named session factory. -
Method Summary
Modifier and TypeMethodDescriptionapply
(Route.Handler next) enabledByDefault
(boolean enabledByDefault) Sets whether all routes in the scope of this decorator instance should be transactional or not (true
by default).Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.jooby.Route.Aware
setRoute
Methods inherited from interface io.jooby.Route.Filter
then, then
-
Constructor Details
-
TransactionalRequest
Creates a new transactional request and attach the to a named session factory.- Parameters:
name
- Name of the session factory.
-
TransactionalRequest
public TransactionalRequest()Creates a new transactional request and attach to the default/first session factory registered.
-
-
Method Details
-
enabledByDefault
Sets whether all routes in the scope of this decorator instance should be transactional or not (true
by default).You can use the
Transactional
annotation to override this option on a single route.- Parameters:
enabledByDefault
- whether routes should be transactional by default- Returns:
- this instance
- See Also:
-
apply
- Specified by:
apply
in interfaceRoute.Filter
-