Session to the
thread for the entire processing of the request.
This class is a concrete expression of the "Open Session in View" pattern, which is a pattern that allows for the lazy loading of associations in web views despite the original transactions already being completed.
This interceptor makes Hibernate Sessions available via the current thread,
which will be autodetected by transaction managers. It is suitable for service layer
transactions via org.
as well as for non-transactional execution (if configured appropriately).
In contrast to OpenSessionInViewFilter, this interceptor is configured
in a Spring application context and can thus take advantage of bean wiring.
Warning
Applying this interceptor to existing logic can cause issues
that have not appeared before, through the use of a single Hibernate
Session for the processing of an entire request. In particular, the
reassociation of persistent objects with a Hibernate Session has to
occur at the very beginning of request processing, to avoid clashes with already
loaded instances of the same objects.
OpenSessionInViewFilter, OpenSessionInterceptor, org.springframework.orm.hibernate5.HibernateTransactionManager , TransactionSynchronizationManager, SessionFactory#getCurrentSession()
| Modifier and Type | Field and Description |
|---|---|
| protected final Log | |
| public static final String | PARTICIPATE_SUFFIX
Suffix that gets appended to the |
| private SessionFactory | sessionFactory
References Deprecated
SessionFactory is deprecated or references (maybe indirectly) at least one deprecated element.
|
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | afterCompletion(WebRequest
the current web request request, Exception exception thrown on handler execution, if any ex)Implements org. Unbind the Hibernate |
| public void | afterConcurrentHandlingStarted(WebRequest
the current request request)Implements org. Called instead of |
| private boolean | |
| private boolean | |
| protected String | getParticipateAttributeName()
Return the name of the request attribute that identifies that a request is already intercepted. |
| public SessionFactory | getSessionFactory()
References Deprecated
SessionFactory is deprecated or references (maybe indirectly) at least one deprecated element.
Return the Hibernate SessionFactory that should be used to create Hibernate Sessions. |
| private SessionFactory | obtainSessionFactory()
References Deprecated
SessionFactory is deprecated or references (maybe indirectly) at least one deprecated element.
|
| protected Session | Returns: the Session to use
References Deprecated
Session is deprecated or references (maybe indirectly) at least one deprecated element.
Open a Session for the SessionFactory that this interceptor uses. |
| public void | postHandle(WebRequest
the current web request request, ModelMap the map of model objects that will be exposed to the view
(may be model)null). Can be used to analyze the exposed model
and/or to add further model attributes, if desired.Implements org. Intercept the execution of a request handler after its successful invocation, right before view rendering (if any). |
| public void | preHandle(WebRequest
the current web request request)Implements org. Open a new Hibernate |
| public void | setSessionFactory(SessionFactory sessionFactory)
References Deprecated
SessionFactory is deprecated or references (maybe indirectly) at least one deprecated element.
Set the Hibernate SessionFactory that should be used to create Hibernate Sessions. |
| logger | back to summary |
|---|---|
| protected final Log logger | |
| PARTICIPATE_SUFFIX | back to summary |
|---|---|
| public static final String PARTICIPATE_SUFFIX Suffix that gets appended to the
| |
| sessionFactory | back to summary |
|---|---|
| private SessionFactory sessionFactory
References Deprecated
See corresponding docs for further information. | |
| OpenSessionInViewInterceptor | back to summary |
|---|---|
| public OpenSessionInViewInterceptor() | |
| afterCompletion | back to summary |
|---|---|
| public void afterCompletion(WebRequest request, Exception ex) throws DataAccessException Implements org. Unbind the Hibernate
| |
| afterConcurrentHandlingStarted | back to summary |
|---|---|
| public void afterConcurrentHandlingStarted(WebRequest request) Implements org. Doc from org. Called instead of
| |
| applySessionBindingInterceptor | back to summary |
|---|---|
| private boolean applySessionBindingInterceptor(WebAsyncManager asyncManager, String key) | |
| decrementParticipateCount | back to summary |
|---|---|
| private boolean decrementParticipateCount(WebRequest request) | |
| getParticipateAttributeName | back to summary |
|---|---|
| protected String getParticipateAttributeName() Return the name of the request attribute that identifies that a request is already intercepted. The default implementation takes the | |
| getSessionFactory | back to summary |
|---|---|
| public SessionFactory getSessionFactory()
References Deprecated
See corresponding docs for further information. Return the Hibernate SessionFactory that should be used to create Hibernate Sessions.
| |
| obtainSessionFactory | back to summary |
|---|---|
| private SessionFactory obtainSessionFactory()
References Deprecated
See corresponding docs for further information. | |
| openSession | back to summary |
|---|---|
| protected Session openSession() throws DataAccessResourceFailureException
References Deprecated
See corresponding docs for further information. Open a Session for the SessionFactory that this interceptor uses. The default implementation delegates to the
| |
| postHandle | back to summary |
|---|---|
| public void postHandle(WebRequest request, ModelMap model) Implements org. Doc from org. Intercept the execution of a request handler after its successful invocation, right before view rendering (if any). Allows for modifying context resources after successful handler execution (for example, flushing a Hibernate Session).
| |
| preHandle | back to summary |
|---|---|
| public void preHandle(WebRequest request) throws DataAccessException Implements org. Open a new Hibernate
| |
| setSessionFactory | back to summary |
|---|---|
| public void setSessionFactory(SessionFactory sessionFactory)
References Deprecated
See corresponding docs for further information. Set the Hibernate SessionFactory that should be used to create Hibernate Sessions. | |