Hibernate中NoSession问题
今天在使用hibernate中
Note note = hibTem.load(Note.class, id);
报了一个could not initialize proxy [cn.entity.Note#11] - no Session 的问题,本人新手,看了好长时间,终于明白看这个问题,
请求的数据流程是这样的:
listDetail.do-->filter-->struts.xml--->action--->execute--service--->dao(session关闭)---->result--->jsp
它在调用时session已经关闭了,配置一下web..xml让它不关闭即可(注意:如果项目中有Filter,必须配置在Filter之前).
<!-- noSession配置 -->
<filter>
<filter-name>NoSession</filter-name>
<filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>NoSession</filter-name>
<url-pattern>/*</url-pattern><!--这里可以写特定的地址-->
</filter-mapping>
配置完就ok了

浙公网安备 33010602011771号