public class TransactionalRequest extends Object implements Route.Decorator
Session and EntityManager to the current request.
The route pipeline runs inside a transaction which is commit on success or rollback in case of
exception.
Once route pipeline is executed the session/entityManager is detached from current request and
closed it.
Usage:
{
install(new HikariModule());
install(new HibernateModule());
decorator(new TransactionalRequest());
get("/handle", ctx -> {
EntityManager handle = require(EntityManager.class);
// work with handle.
});
}
NOTE: This is NOT the open session in view pattern. Persistent objects must be fully initialized
to be encoded/rendered to the client. Otherwise, Hibernate results in
LazyInitializationException.| Constructor and Description |
|---|
TransactionalRequest()
Creates 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.
|
| Modifier and Type | Method and Description |
|---|---|
Route.Handler |
apply(Route.Handler next) |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitsetRoute, then, thenpublic TransactionalRequest(@Nonnull String name)
name - Name of the session factory.public TransactionalRequest()
@Nonnull public Route.Handler apply(@Nonnull Route.Handler next)
apply in interface Route.DecoratorCopyright © 2019. All rights reserved.