java.lang.Object
io.jooby.hibernate.SessionRequest
- All Implemented Interfaces:
io.jooby.Route.Aware,io.jooby.Route.Filter
Attach
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());
use(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.- Author:
- Benjamin Quinn
-
Constructor Summary
ConstructorsConstructorDescriptionCreates 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. -
Method Summary
Modifier and TypeMethodDescriptionio.jooby.Route.Handlerapply(io.jooby.Route.Handler next) io.jooby.ServiceKey<org.hibernate.SessionFactory>Get the service key for accessing to the configuredSessionFactoryservice.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.jooby.Route.Aware
setRouteMethods inherited from interface io.jooby.Route.Filter
then, then
-
Constructor Details
-
SessionRequest
Creates a new session request and attach the to a named session factory.- Parameters:
name- Name of the session factory.
-
SessionRequest
public SessionRequest()Creates a new session request and attach to the default/first session factory registered.
-
-
Method Details
-
apply
@NonNull public io.jooby.Route.Handler apply(@NonNull io.jooby.Route.Handler next) - Specified by:
applyin interfaceio.jooby.Route.Filter
-
getSessionFactoryKey
@NonNull public io.jooby.ServiceKey<org.hibernate.SessionFactory> getSessionFactoryKey()Get the service key for accessing to the configuredSessionFactoryservice.- Returns:
- The service key for accessing to the configured
SessionFactoryservice.
-