public class OpenEntityManagerInViewInterceptor extends EntityManagerFactoryAccessor implements AsyncWebRequestInterceptor
This interceptor makes JPA EntityManagers available via the current thread,
which will be autodetected by transaction managers. It is suitable for service
layer transactions via JpaTransactionManager
or JtaTransactionManager
as well
as for non-transactional read-only execution.
In contrast to OpenEntityManagerInViewFilter
, this interceptor is set
up in a Spring application context and can thus take advantage of bean wiring.
OpenEntityManagerInViewFilter
,
JpaTransactionManager
,
SharedEntityManagerCreator
,
TransactionSynchronizationManager
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
PARTICIPATE_SUFFIX
Suffix that gets appended to the EntityManagerFactory toString
representation for the "participate in existing entity manager
handling" request attribute.
|
logger
Constructor and Description |
---|
OpenEntityManagerInViewInterceptor() |
Modifier and Type | Method and Description |
---|---|
void |
afterCompletion(WebRequest request,
java.lang.Exception ex)
Callback after completion of request processing, that is, after rendering
the view.
|
void |
afterConcurrentHandlingStarted(WebRequest request)
Called instead of
postHandle and afterCompletion , when the
handler started handling the request concurrently. |
protected java.lang.String |
getParticipateAttributeName()
Return the name of the request attribute that identifies that a request is
already filtered.
|
void |
postHandle(WebRequest request,
ModelMap model)
Intercept the execution of a request handler after its successful
invocation, right before view rendering (if any).
|
void |
preHandle(WebRequest request)
Intercept the execution of a request handler before its invocation.
|
createEntityManager, getEntityManagerFactory, getJpaPropertyMap, getPersistenceUnitName, getTransactionalEntityManager, obtainEntityManagerFactory, setBeanFactory, setEntityManagerFactory, setJpaProperties, setJpaPropertyMap, setPersistenceUnitName
public static final java.lang.String PARTICIPATE_SUFFIX
public void preHandle(WebRequest request) throws DataAccessException
WebRequestInterceptor
Allows for preparing context resources (such as a Hibernate Session) and expose them as request attributes or as thread-local objects.
preHandle
in interface WebRequestInterceptor
request
- the current web requestDataAccessException
public void postHandle(WebRequest request, @Nullable ModelMap model)
WebRequestInterceptor
Allows for modifying context resources after successful handler execution (for example, flushing a Hibernate Session).
postHandle
in interface WebRequestInterceptor
request
- the current web requestmodel
- the map of model objects that will be exposed to the view
(may be null
). Can be used to analyze the exposed model
and/or to add further model attributes, if desired.public void afterCompletion(WebRequest request, @Nullable java.lang.Exception ex) throws DataAccessException
WebRequestInterceptor
Note: Will only be called if this interceptor's preHandle
method has successfully completed!
afterCompletion
in interface WebRequestInterceptor
request
- the current web requestex
- exception thrown on handler execution, if anyDataAccessException
public void afterConcurrentHandlingStarted(WebRequest request)
AsyncWebRequestInterceptor
postHandle
and afterCompletion
, when the
handler started handling the request concurrently.afterConcurrentHandlingStarted
in interface AsyncWebRequestInterceptor
request
- the current requestprotected java.lang.String getParticipateAttributeName()
PARTICIPATE_SUFFIX