在做ssh项目练习的时候出现问题:

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role

原因在于hibernate的懒加载出现的问题。
在多方中的一方的配置没有指定加载方式,而且一方中的多方是懒加载,因此在获取一方的时候一方是获取到了,但是再获取多方的时候session已经关闭了,这时候会获取不到多方信息,因此报错。 
解决办法:
将一方中的多方(one-to-many)的加载方式改为立刻加载,而多方中的一方(many-to-one)改为懒加载即可。
即在一对多的一方加上 lazy="false"(one-to-many)

ssh框架错误:org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role。的更多相关文章

  1. hibernate延迟加载org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.javakc.hibernate.onetomany.entity.DeptEntity.emp, could not initialize proxy - no Session

    public static void main(String[] args) {  DeptEntity dept = getDept("402882e762ae888d0162ae888e ...

  2. 使用hibernate从一方获取多方信息时报错:org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role

    引起原因:hibernate加载关联对象的方式有懒加载方式和立即加载方式. 如果在多对一的配置中没有指定加载方式,而一对多的配置中指定了懒加载方式,因此在获取一方是可获取到值,而获取多方时sessio ...

  3. 多对多关联懒加载导致failed to lazily initialize a collection of role: 实体类, could not initialize proxy - no Session 追加配置fetch = FetchType.EAGER解决

    一篇文章需要关联很多个标签,所以他们呈一对多(多对多)的关系 org.springframework.web.util.NestedServletException: Request processi ...

  4. org.hibernate.LazyInitializationException: failed to lazily initialize

    今天搞了一上午,都在解决这个问题:org.hibernate.LazyInitializationException: failed to lazily initialize 原因很简单,是在非法的s ...

  5. 问题:org.hibernate.LazyInitializationException: failed to lazily initialize

    今天搞了一上午,都在解决这个问题:org.hibernate.LazyInitializationException: failed to lazily initialize 原因很简单,是在非法的s ...

  6. Hibernate加载数据失败failed to lazily initialize a collection of role

    在测试获取数据库中的数据或者在页面获取时,有时会遇到这样的错误提示: failed to lazily initialize a collection of role: com.exam.entity ...

  7. 【转】hibernate懒加载的问题,failed to lazily initialize a collection of role

    hibernate懒加载的问题,failed to lazily initialize a collection of role hibernate懒加载的问题,failed to lazily in ...

  8. failed to lazily initialize a collection of role 异常

    最近在通过配置实体类的方式,正向自动扫描注解方式配置的hibernate类文件来生成数据库的方法搭建环境,遇到了许多问题. 通过数据库配置hibernate的时候,大家都知道是在实体类对应生成的.hb ...

  9. failed to lazily initialize a collection of role

    可能修复了一个重大的偶尔发生的几乎难以察觉的并且到现在我也没能理解的bug...有时(经常)调用updateNotNullfield方法(原理是从数据库中get一个对象,然后把原对象中非空的值赋予它, ...

随机推荐

  1. git杂记-记录每次更新到仓库

    git status 和 git diff的运用 git status 记录的是关于仓库文件是否有变更,例如是否被修改,是否被添加到暂村区.至于文件更改了什么内容该命令并不关心: git status ...

  2. 分数规划(Bzoj1486: [HNOI2009]最小圈)

    题面 传送门 分数规划 分数规划有什么用? 可以把带分数的最优性求解式化成不带除发的运算 假设求max{\(\frac{a}{b},b>0\)} 二分一个权值\(k\) 令\(\frac{a}{ ...

  3. Fatal error: Namespace declaration statement has to be the very first statement or after any declare call in the script in

    学习php的命名空间,直接把手册的代码粘贴过来,却报错了:Fatal error: Namespace declaration statement has to be the very first s ...

  4. Java中int与Integer的区别

    转自https://www.cnblogs.com/guodongdidi/p/6953217.html import java.lang.Integer; public class intDemo{ ...

  5. MUI框架-12-使用原生底部选项卡(凸出图标案例)

    MUI框架-12-使用原生底部选项卡(凸出图标案例) 今天,用 mui 做 app 时,遇到了可能各位都遇到过的头疼问题:底部中间图标凸起,如下图: 最后有源代码 [提示]:有人问我在 HBuilde ...

  6. PowerDNS Authoritative Server 3.3 发布

    PowerDNS Authoritative Server 3.3 发布,该版本改进了不同验证器的交互操作,修复了不少 bug. PowerDNS Authoritative Server (PDNS ...

  7. HTML 的 style 属性

    style 属性用于改变 HTML 元素的样式. This text is in Verdana and red This text is in Times and blue This text is ...

  8. Ionic控件之——按钮(Button)

    Ionic提供丰富的按钮特性,足以满足大部分的按钮实现需求. 一.HTML实现一个简单按钮: <button class="button"> 我是按钮 </but ...

  9. [EffectiveC++]item21:Don't try to return a reference when you must return an object

  10. Centos 7 iptables配置

    systemctl status firewalld.service #检测是否开启了firewall systemctl stop firewalld.service #关闭firewall syt ...