Class OpenSessionInterceptor
java.lang.Object
org.springframework.orm.hibernate5.support.OpenSessionInterceptor
- All Implemented Interfaces:
org.aopalliance.aop.Advice
,org.aopalliance.intercept.Interceptor
,org.aopalliance.intercept.MethodInterceptor
,org.springframework.beans.factory.InitializingBean
public class OpenSessionInterceptor
extends Object
implements org.aopalliance.intercept.MethodInterceptor, org.springframework.beans.factory.InitializingBean
Simple AOP Alliance
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.
- Since:
- 4.2
- Author:
- Juergen Hoeller
- See Also:
-
OpenSessionInViewInterceptor
OpenSessionInViewFilter
HibernateTransactionManager
TransactionSynchronizationManager
SessionFactory.getCurrentSession()
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Return the Hibernate SessionFactory that should be used to create Hibernate Sessions.invoke
(org.aopalliance.intercept.MethodInvocation invocation) 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.
-
Constructor Details
-
OpenSessionInterceptor
public OpenSessionInterceptor()
-
-
Method Details
-
setSessionFactory
Set the Hibernate SessionFactory that should be used to create Hibernate Sessions. -
getSessionFactory
Return the Hibernate SessionFactory that should be used to create Hibernate Sessions. -
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
-
invoke
@Nullable public Object invoke(org.aopalliance.intercept.MethodInvocation invocation) throws Throwable - Specified by:
invoke
in interfaceorg.aopalliance.intercept.MethodInterceptor
- Throws:
Throwable
-
openSession
protected Session openSession(SessionFactory sessionFactory) throws org.springframework.dao.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".- Parameters:
sessionFactory
- the SessionFactory to use- Returns:
- the Session to use
- Throws:
org.springframework.dao.DataAccessResourceFailureException
- if the Session could not be created- Since:
- 5.0
- See Also:
-