If you use OpenSessionInViewFilter then it can be extented for it:
Code:
<filter>
<filter-name>Session Filter</filter-name>
<filter-class>com.example.ExtendedOpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>entityInterceptorName</param-name>
<param-value>historyInterceptor</param-value>
</init-param>
</filter>
Code:
<bean id="historyInterceptor" class="com.example.MyInterceptor" scope="prototype" />
Code:
public class ExtendedOpenSessionInViewFilter extends OpenSessionInViewFilter {
private String entityInterceptorName;
public void setEntityInterceptorName(final String entityInterceptorName) {
this.entityInterceptorName = entityInterceptorName;
}
@Override
protected Session getSession(SessionFactory sessionFactory) {
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
Interceptor entityInterceptor = (Interceptor) wac.getBean(entityInterceptorName, Interceptor.class);
Session session = SessionFactoryUtils.getSession(sessionFactory, entityInterceptor, null);
FlushMode flushMode = getFlushMode();
if (flushMode != null) {
session.setFlushMode(flushMode);
}
return session;
}
}