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
Deprecated
as a consequence of
SessionFactory being deprecated.
|
| 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. Session from the thread and close it.
|
| public void | afterConcurrentHandlingStarted(WebRequest
the current request request)Implements org. postHandle and afterCompletion, when the
handler started handling the request concurrently.
|
| 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()
Deprecated
as a consequence of
Return the Hibernate SessionFactory that should be used to create Hibernate Sessions.
SessionFactory being deprecated.
|
| private SessionFactory | |
| protected Session | Returns: the Session to use
Deprecated
as a consequence of
Open a Session for the SessionFactory that this interceptor uses.
Session being deprecated.
|
| 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. |
| public void | preHandle(WebRequest
the current web request request)Implements org. Session according and bind it to the thread via the
TransactionSynchronizationManager.
|
| public void | setSessionFactory(SessionFactory sessionFactory)
Deprecated
as a consequence of
Set the Hibernate SessionFactory that should be used to create Hibernate Sessions.
SessionFactory being deprecated.
|
| 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
Deprecated as a consequence of | |
| 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()
Deprecated as a consequence of Return the Hibernate SessionFactory that should be used to create Hibernate Sessions.
| |
| obtainSessionFactory | back to summary |
|---|---|
| private SessionFactory obtainSessionFactory()
Deprecated as a consequence of | |
| openSession | back to summary |
|---|---|
| protected Session openSession() throws DataAccessResourceFailureException
Deprecated as a consequence of 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)
Deprecated as a consequence of Set the Hibernate SessionFactory that should be used to create Hibernate Sessions. | |