类 OpenSessionInterceptor
- java.lang.Object
- org.springframework.orm.hibernate5.support.OpenSessionInterceptor
- 所有已实现的接口:
Advice
,Interceptor
,MethodInterceptor
,InitializingBean
public class OpenSessionInterceptor extends Object implements MethodInterceptor, InitializingBean
Simple AOP AllianceMethodInterceptor
implementation that binds a new HibernateSession
for each method invocation, if none bound before.This is a simple Hibernate Session scoping interceptor along the lines of
OpenSessionInViewInterceptor
, just for use with AOP setup instead of MVC setup. It opens a newSession
with flush mode "MANUAL" since the Session is only meant for reading, except when participating in a transaction.- 从以下版本开始:
- 4.2
- 作者:
- Juergen Hoeller
- 另请参阅:
OpenSessionInViewInterceptor
,OpenSessionInViewFilter
,HibernateTransactionManager
,TransactionSynchronizationManager
,SessionFactory.getCurrentSession()
构造器概要
构造器 构造器 说明 OpenSessionInterceptor()
方法概要
所有方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.SessionFactory
getSessionFactory()
Return the Hibernate SessionFactory that should be used to create Hibernate Sessions.Object
invoke(MethodInvocation invocation)
Implement this method to perform extra treatments before and after the invocation.protected Session
openSession()
已过时。as of 5.0, in favor ofopenSession(SessionFactory)
protected Session
openSession(SessionFactory sessionFactory)
Open a Session for the given SessionFactory.void
setSessionFactory(SessionFactory sessionFactory)
Set the Hibernate SessionFactory that should be used to create Hibernate Sessions.
构造器详细资料
OpenSessionInterceptor
public OpenSessionInterceptor()
方法详细资料
setSessionFactory
public void setSessionFactory(@Nullable SessionFactory sessionFactory)
Set the Hibernate SessionFactory that should be used to create Hibernate Sessions.
getSessionFactory
@Nullable public SessionFactory getSessionFactory()
Return the Hibernate SessionFactory that should be used to create Hibernate Sessions.
afterPropertiesSet
public void afterPropertiesSet()
从接口复制的说明:InitializingBean
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
- 指定者:
afterPropertiesSet
在接口中InitializingBean
invoke
public Object invoke(MethodInvocation invocation) throws Throwable
从接口复制的说明:MethodInterceptor
Implement this method to perform extra treatments before and after the invocation. Polite implementations would certainly like to invokeJoinpoint.proceed()
.- 指定者:
invoke
在接口中MethodInterceptor
- 参数:
invocation
- the method invocation joinpoint- 返回:
- the result of the call to
Joinpoint.proceed()
; might be intercepted by the interceptor - 抛出:
Throwable
- if the interceptors or the target object throws an exception
openSession
protected Session openSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException
Open a Session for the given SessionFactory.The default implementation delegates to the
SessionFactory.openSession()
method and sets theSession
's flush mode to "MANUAL".- 参数:
sessionFactory
- the SessionFactory to use- 返回:
- the Session to use
- 抛出:
DataAccessResourceFailureException
- if the Session could not be created- 从以下版本开始:
- 5.0
- 另请参阅:
FlushMode.MANUAL
openSession
@Deprecated @Nullable protected Session openSession() throws DataAccessResourceFailureException
已过时。as of 5.0, in favor ofopenSession(SessionFactory)
Open a Session for the given SessionFactory.