在联级查询中如果不配置OpenSessionInViewFilter则flex端将无法显示数据,但配置了OpenSessionInViewFilter
将
<filter> <filter-name>hibernateFilter</filter-name> <filter-class>org.tianwei.common.MyOpenSessionInViewFilter</filter-class> <init-param> <param-name>singleSession</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>hibernateFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
中的 <param-value>true</param-value>设置成true,则不能调用hibernate的更操作功能,折磨了几天的。好在最后在http://xuliangyong.iteye.com/blog/144818 找到解决的方法,就是重写OpenSessionInViewFilter类
上面的配置是重写之后的配置,希望对大家有用。同时非常感谢xly_971223,
public class MyOpenSessionInViewFilter extends OpenSessionInViewFilter {
protected Session getSession(SessionFactory sessionFactory)
throws DataAccessResourceFailureException {
Session session = SessionFactoryUtils.getSession(sessionFactory, true);
this.setFlushMode(FlushMode.AUTO);
/*FlushMode flushMode = getFlushMode();
if (flushMode != null) {
session.setFlushMode(flushMode);
} */
return session;
}
protected void closeSession(Session session, SessionFactory sessionFactory){
session.flush();
super.closeSession(session, sessionFactory);
}
}