failed to lazily initialize a collection of role:XXX, no sessi
系统 框架 springMVC+hibernate
这种情况 由于 hibernate 的 懒汉机制,和 Spring 事务机制(不确定)造成的
由于 spring 配置的时候,在service 层关闭的了会话,controller(view层)根据对象转json的时候,由于
get的该属性,懒加载 执行了一次,由于session 已经关闭了,所以 就回报错
解决方法:
1. spring 配置的时候,事务提交,配置在 view层
2. 转json的忽略该字段,@JsonIgnore
各有利弊,根据具体情况定。目前没有找到其他合理的方法,求推荐!!!
failed to lazily initialize a collection of role:XXX, no sessi的更多相关文章
- Hibernate加载数据失败failed to lazily initialize a collection of role
在测试获取数据库中的数据或者在页面获取时,有时会遇到这样的错误提示: failed to lazily initialize a collection of role: com.exam.entity ...
- failed to lazily initialize a collection of role
可能修复了一个重大的偶尔发生的几乎难以察觉的并且到现在我也没能理解的bug...有时(经常)调用updateNotNullfield方法(原理是从数据库中get一个对象,然后把原对象中非空的值赋予它, ...
- 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 ...
- ssh框架错误:org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role。
在做ssh项目练习的时候出现问题: org.hibernate.LazyInitializationException: failed to lazily initialize a collectio ...
- FetchType.LAZY 时属性加上@JsonIgnore,避免返回时报错:Could not write JSON: failed to lazily initialize a collection of role
[示例] @OneToMany(fetch=FetchType.LAZY) @JsonIgnore @Fetch(FetchMode.SELECT) @Cascade(value={CascadeTy ...
- failed to lazily initialize a collection of role 异常
最近在通过配置实体类的方式,正向自动扫描注解方式配置的hibernate类文件来生成数据库的方法搭建环境,遇到了许多问题. 通过数据库配置hibernate的时候,大家都知道是在实体类对应生成的.hb ...
- 【转】hibernate懒加载的问题,failed to lazily initialize a collection of role
hibernate懒加载的问题,failed to lazily initialize a collection of role hibernate懒加载的问题,failed to lazily in ...
- 多对多关联懒加载导致failed to lazily initialize a collection of role: 实体类, could not initialize proxy - no Session 追加配置fetch = FetchType.EAGER解决
一篇文章需要关联很多个标签,所以他们呈一对多(多对多)的关系 org.springframework.web.util.NestedServletException: Request processi ...
- ERROR LazyInitializationException:19 - failed to lazily initialize a collection of role: com.goodfan.entity.BeanA.beanB, no session or session was closed
1. 问题, 当使用JSONArray.fromObject(List<BeanA>)时, beanA中含有BeanB的属性beanB时,会报这个错 2. 解决办法: 使用jsonconf ...
随机推荐
- crontab中执行任务定位到秒级
每秒执行一次: * * * * * /bin/sleep 1 ; echo "1"
- shell 套用expect
先用if 判断expect有没有安装 没有就yum install expect #!/bin/bash passwd='123456' /usr/bin/expect <<-EOF se ...
- jQuery 中的事件冒泡和阻止默认行为
1.事件冒泡 <%@ page language="java" import="java.util.*" pageEncoding="utf-8 ...
- 下载更新文件后,调用安装器自动安装apk文件
在更新操作时,下载新apk之后,往往需要自动安装新apk,用以下代码即可安装下载在本地的apk文件(apkFile) Intent intent = new Intent(); intent.setA ...
- C# 根据年月日获取星期几方法
#region 根据年月日计算星期几(Label2.Text=CaculateWeekDay(2004,12,9);) /// <summary> /// 根据年月日计算星期几(Label ...
- iOS知识总结
mindNote文件下载地址 : 知识总结.zip
- JavaScript Array 常用函数整理
按字母顺序整理 索引 Array.prototype.concat() Array.prototype.filter() Array.prototype.indexOf() Array.prototy ...
- Swift 必备开发库10个
1.CryptoSwift swift加密库, 支持md5,sha1,sha224,sha256... github地址: https://github.com/krzyzanowskim/Crypt ...
- manifest中读取<meta-data>
meta-data在清单文件中主要有以下用法: <application> <meta-data android:value="a1" android ...
- 在命令行下使用perl
http://blog.sina.com.cn/s/blog_4af3f0d20100g9oz.html aaa@domain.com 2aaa@domain.com 111bbb@home.com ...