public class OpenSessionInterceptor extends Object implements MethodInterceptor, org.springframework.beans.factory.InitializingBean
MethodInterceptor
implementation that binds a new
Hibernate Session
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 new Session
with flush mode "MANUAL" since the
Session is only meant for reading, except when participating in a transaction.
OpenSessionInViewInterceptor
,
OpenSessionInViewFilter
,
HibernateTransactionManager
,
TransactionSynchronizationManager
,
SessionFactory.getCurrentSession()
Constructor and Description |
---|
OpenSessionInterceptor() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
SessionFactory |
getSessionFactory()
Return the Hibernate SessionFactory that should be used to create Hibernate Sessions.
|
Object |
invoke(MethodInvocation invocation) |
protected Session |
openSession()
Open a Session for the SessionFactory that this interceptor uses.
|
void |
setSessionFactory(SessionFactory sessionFactory)
Set the Hibernate SessionFactory that should be used to create Hibernate Sessions.
|
public void setSessionFactory(SessionFactory sessionFactory)
public SessionFactory getSessionFactory()
public void afterPropertiesSet()
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
public Object invoke(MethodInvocation invocation) throws Throwable
invoke
in interface MethodInterceptor
Throwable
protected Session openSession() throws org.springframework.dao.DataAccessResourceFailureException
The default implementation delegates to the SessionFactory.openSession()
method and sets the Session
's flush mode to "MANUAL".
org.springframework.dao.DataAccessResourceFailureException
- if the Session could not be createdFlushMode.MANUAL