public class OpenSessionInterceptor extends Object implements org.aopalliance.intercept.MethodInterceptor, InitializingBean
Simple AOP Alliance org.aopalliance.intercept.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.
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
afterPropertiesSet() |
|
public SessionFactory |
getSessionFactory()Return the Hibernate SessionFactory that should be used to create Hibernate Sessions. |
|
public Object |
invoke(org.aopalliance.intercept.MethodInvocation invocation) |
|
protected Session |
openSession(SessionFactory sessionFactory)Open a Session for the given SessionFactory. |
|
public void |
setSessionFactory(SessionFactory sessionFactory)Set the Hibernate SessionFactory that should be used to create Hibernate Sessions. |
Return the Hibernate SessionFactory that should be used to create Hibernate Sessions.
Open a Session for the given SessionFactory.
The default implementation delegates to the SessionFactory.openSession method and sets the Session's flush mode to "MANUAL".
sessionFactory - the SessionFactory to useSet the Hibernate SessionFactory that should be used to create Hibernate Sessions.