zoukankan      html  css  js  c++  java
  • failed to lazily initialize a collection of role: com.itheima.bos.domain.Staff.decidedzones, could not initialize proxy – no Session

    问题出在:could not initialize proxy – no Session at  无法初始化代理-没有session。  证明获取不到session,访问action的时候报了500错误,

    配置懒加载一定要在web.xml开头配置代码,放在其他位置无效。

    解决办法:这个是 由于web.xml没有配置懒加载。名词解析:延迟加载,也叫懒加载,它是Hibernate为提高程序执行效率而提供的一种机制,即只有真正使用该对象的数据时才会创建。

    在web.xml里面配置懒加载,代码如下:

      <!-- 配置过滤器,解决hibernate延迟加载问题 -->  
    
    <filter>  
    
    <filter-name>openSessionInView</filter-name> 
    
     <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>  
    
    </filter>  
    
    <filter-mapping>  <filter-name>openSessionInView</filter-name>  <url-pattern>/*</url-pattern>  
    
    </filter-mapping>

    最最最重要的一点是,其他博客都没有提到的,但是有必须要做的,配置懒加载一定要在web.xml开头配置代码。

    我的web.xml配置如下:

    这样即可完美解决。

  • 相关阅读:
    读《持续交付2.0》
    “兼职”运维的常用命令
    技术管理者怎样跳出“泥潭”
    使用RabbitMQ实现接口补偿
    dotNET Core 中怎样操作 AD?
    dotNET Core实现分布式环境下的流水号唯一
    Git 远程仓库
    分之管理
    git 基本操作----git diff
    git 基本操作----git reset、log
  • 原文地址:https://www.cnblogs.com/karmapeng/p/9715956.html
Copyright © 2011-2022 走看看