public class SessionRequest extends Object implements Route.Decorator
Session and EntityManager to the current request.
The active Session is accessible via SessionFactory.getCurrentSession() for the
duration of the route pipeline.
Once route pipeline is executed the session/entityManager is detached from current request and
closed.
Usage:
{
install(new HikariModule());
install(new HibernateModule());
decorator(new SessionRequest());
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 |
|---|
SessionRequest()
Creates a new session request and attach to the default/first session factory registered.
|
SessionRequest(String name)
Creates a new session request and attach the to a named session factory.
|
| Modifier and Type | Method and Description |
|---|---|
Route.Handler |
apply(Route.Handler next) |
ServiceKey<org.hibernate.SessionFactory> |
getSessionFactoryKey()
Get the service key for accessing to the configured
SessionFactory service. |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitthen, thensetRoutepublic SessionRequest(@Nonnull String name)
name - Name of the session factory.public SessionRequest()
@Nonnull public Route.Handler apply(@Nonnull Route.Handler next)
apply in interface Route.Decorator@Nonnull public ServiceKey<org.hibernate.SessionFactory> getSessionFactoryKey()
SessionFactory service.SessionFactory service.Copyright © 2020. All rights reserved.