zoukankan      html  css  js  c++  java
  • 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了



  • 相关阅读:
    NACBD
    周总结7
    周总结6
    团队题目——TD课程通
    移动端疫情展示
    周总结5
    每周总结4
    每周总结3
    每周总结2
    求最大子数组
  • 原文地址:https://www.cnblogs.com/hx1098/p/9519720.html
Copyright © 2011-2022 走看看