类 OpenEntityManagerInViewInterceptor
- java.lang.Object
- org.springframework.orm.jpa.EntityManagerFactoryAccessor
- org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor
public class OpenEntityManagerInViewInterceptor extends EntityManagerFactoryAccessor implements AsyncWebRequestInterceptor
Spring web request interceptor that binds a JPA EntityManager to the thread for the entire processing of the request. Intended for the "Open EntityManager in View" pattern, i.e. to allow for lazy loading in web views despite the original transactions already being completed.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
orJtaTransactionManager
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.- 从以下版本开始:
- 2.0
- 作者:
- Juergen Hoeller
- 另请参阅:
OpenEntityManagerInViewFilter
,JpaTransactionManager
,SharedEntityManagerCreator
,TransactionSynchronizationManager
字段概要
字段 修饰符和类型 字段 说明 static String
PARTICIPATE_SUFFIX
Suffix that gets appended to the EntityManagerFactory toString representation for the "participate in existing entity manager handling" request attribute.从类继承的字段 org.springframework.orm.jpa.EntityManagerFactoryAccessor
logger
构造器概要
构造器 构造器 说明 OpenEntityManagerInViewInterceptor()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
afterCompletion(WebRequest request, Exception ex)
Callback after completion of request processing, that is, after rendering the view.void
afterConcurrentHandlingStarted(WebRequest request)
Called instead ofpostHandle
andafterCompletion
, when the handler started handling the request concurrently.protected 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.从类继承的方法 org.springframework.orm.jpa.EntityManagerFactoryAccessor
createEntityManager, getEntityManagerFactory, getJpaPropertyMap, getPersistenceUnitName, getTransactionalEntityManager, obtainEntityManagerFactory, setBeanFactory, setEntityManagerFactory, setJpaProperties, setJpaPropertyMap, setPersistenceUnitName
字段详细资料
PARTICIPATE_SUFFIX
public static final String PARTICIPATE_SUFFIX
Suffix that gets appended to the EntityManagerFactory toString representation for the "participate in existing entity manager handling" request attribute.
构造器详细资料
OpenEntityManagerInViewInterceptor
public OpenEntityManagerInViewInterceptor()
方法详细资料
preHandle
public void preHandle(WebRequest request) throws DataAccessException
从接口复制的说明:WebRequestInterceptor
Intercept the execution of a request handler before its invocation.Allows for preparing context resources (such as a Hibernate Session) and expose them as request attributes or as thread-local objects.
- 指定者:
preHandle
在接口中WebRequestInterceptor
- 参数:
request
- the current web request- 抛出:
DataAccessException
postHandle
public void postHandle(WebRequest request, @Nullable ModelMap model)
从接口复制的说明:WebRequestInterceptor
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).
- 指定者:
postHandle
在接口中WebRequestInterceptor
- 参数:
request
- the current web requestmodel
- the map of model objects that will be exposed to the view (may benull
). Can be used to analyze the exposed model and/or to add further model attributes, if desired.
afterCompletion
public void afterCompletion(WebRequest request, @Nullable Exception ex) throws DataAccessException
从接口复制的说明:WebRequestInterceptor
Callback after completion of request processing, that is, after rendering the view. Will be called on any outcome of handler execution, thus allows for proper resource cleanup.Note: Will only be called if this interceptor's
preHandle
method has successfully completed!- 指定者:
afterCompletion
在接口中WebRequestInterceptor
- 参数:
request
- the current web requestex
- exception thrown on handler execution, if any- 抛出:
DataAccessException
afterConcurrentHandlingStarted
public void afterConcurrentHandlingStarted(WebRequest request)
从接口复制的说明:AsyncWebRequestInterceptor
Called instead ofpostHandle
andafterCompletion
, when the handler started handling the request concurrently.- 指定者:
afterConcurrentHandlingStarted
在接口中AsyncWebRequestInterceptor
- 参数:
request
- the current request
getParticipateAttributeName
protected String getParticipateAttributeName()
Return the name of the request attribute that identifies that a request is already filtered. Default implementation takes the toString representation of the EntityManagerFactory instance and appends ".FILTERED".- 另请参阅:
PARTICIPATE_SUFFIX