SSH整合中could not initialize proxy - no Session问题的OpenSessionInView解决办法
问题的解决方法主要有两种:
1、将<many-to-one>? & <set> 中设置 lazy="false"。
2、OpenSessionInView解决办法。
后者不需要更改映射文件的配置即可解决这个问题,Neo觉得比较好。具体做法如下:
(第一步)
在web.xml中加入如下内容:
<!-- 实现在Spring管理Hibernate时的延迟加载。如果去掉会导致延迟加载出现问题。 -->
(第二步)
重写OpenSessionInViewFilter类。方法:将Spring源码包中OpenSessionInViewFilter 源代码复制过来,
将private FlushMode flushMode = FlushMode.NEVER;改成private FlushMode flushMode = FlushMode.AUTO;保存即可。
然后将web.xml中的类配置为自己改写后的类名。