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
        class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilterclass>
    
    
     NoSession
     /*
    

 

配置完就ok了

 



你可能感兴趣的:(Hibernate中NoSession问题)