异常: could not initialize proxy - no Session;
Hibernate: select applicatio0_.api_application_id as api_appl1_0_, applicatio0_.application_description as applicat2_0_, applicatio0_.application_is_service as applicat3_0_, applicatio0_.application_key as applicat4_0_, applicatio0_.application_name as applicat5_0_, applicatio0_.application_secret as applicat6_0_, applicatio0_.application_type as applicat7_0_, applicatio0_.developer_id as develope8_0_, applicatio0_.developer_name as develope9_0_, applicatio0_.service_encoder as service10_0_, applicatio0_.insert_time as insert_11_0_, applicatio0_.last_update_time as last_up12_0_, applicatio0_.service_need_sign as service13_0_, applicatio0_.api_service_id as api_ser14_0_, applicatio0_.service_router_url as service15_0_, applicatio0_.service_status as service16_0_, applicatio0_.service_vm_ips as service17_0_ from api_application applicatio0_ where 1=1 limit ? 2017-12-25 17:52:07.582 WARN 3992 --- [nio-8085-exec-8] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: failed to lazily initialize a collection of role: com.curiousby.baoyou.cn.showandshare.application.developmanage.entity.po.Application.applicationInterfaceList, could not initialize proxy - no Session; nested exception is com.fasterxml.jackson.databind.JsonMappingException: failed to lazily initialize a collection of role: com.curiousby.baoyou.cn.showandshare.application.developmanage.entity.po.Application.applicationInterfaceList, could not initialize proxy - no Session (through reference chain: com.curiousby.baoyou.cn.showandshare.application.developmanage.hibernate.PageFinder["data"]->java.util.ArrayList[0]->com.curiousby.baoyou.cn.showandshare.application.developmanage.entity.po.Application["applicationInterfaceList"]) 2017-12-25 17:52:07.582 WARN 3992 --- [nio-8085-exec-8] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: failed to lazily initialize a collection of role: com.curiousby.baoyou.cn.showandshare.application.developmanage.entity.po.Application.applicationInterfaceList, could not initialize proxy - no Session; nested exception is com.fasterxml.jackson.databind.JsonMappingException: failed to lazily initialize a collection of role: com.curiousby.baoyou.cn.showandshare.application.developmanage.entity.po.Application.applicationInterfaceList, could not initialize proxy - no Session (through reference chain: com.curiousby.baoyou.cn.showandshare.application.developmanage.hibernate.PageFinder["data"]->java.util.ArrayList[0]->com.curiousby.baoyou.cn.showandshare.application.developmanage.entity.po.Application["applicationInterfaceList"])
解决方法:
1.
JPA Hibernate禁止懒加载
2.
在properties文件中添加 配置信息 spring.session.store-type=none
3.
在application.properties中加入如下配置: spring.jpa.open-in-view=true
4.
@ManyToOne(fetch = FetchType.LAZY)
捐助开发者
在兴趣的驱动下,写一个免费
的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(支持支付宝和微信 以及扣扣群),没钱捧个人场,谢谢各位。
个人主页:http://knight-black-bob.iteye.com/
谢谢您的赞助,我会做的更好!
相关推荐
Hibernate-nosession浅谈代码案例。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
Springboot+hibernate简单的增删改查,完整的controller、service、dao、entity封装
简单的springboot的学习项目实例,使用了hibernate连接mysql数据库,进行简单的插入和查询操作,项目中已经包含依赖的jar包和数据库脚本,只需要创建配置的数据库并使用数据库脚本建立表即可。
springboot + hibernate + gradle结合使用的工程,其中没有swagger定义的model类,但是springboot + hibernate + gradle部分是完全正确的,可供使用着参考
springboot集成hibernate无jpa,在dao中使用SessionFactory操作数据库
springboot2.0多数据源集成hibernate配置hibernateDaoSupport, dao层继承hibernateDaoSupport, 不使用jpa方式。
springboot+hibernate+html增删改查demo,可以运行,(包含运行帮助文档)
直接执行Main方法,或运行在Tomcat
基于springboot最新版本2.1.4.RELEASE,采用jpa为dao层框架,配置redis(redisson)为hibernate的二级缓存。
Springboot整合Hibernate thymeleaf,添删改查,分页查询等,单元测试,亲测百分之百可运行,网上好多功能不全,甚至无法运行,这个是我自己亲自跑的,绝对没有问题
Idea创建SpringBoot项目整合Hibernate
springboot+hibernate+thymeleaf分页增删改查demo,可以看使用说明运行项目
No Hibernate Session bound to thread,没有绑定线程解决办法,找了好久才找到的
springboot + hibernate 的第一个项目
springboot利用jpa连接hibernate,并进行生成表,对表的增加,删除,查询操作用法2
springboot+hibernate+gradle+mysql的简单例子,具体参考https://blog.csdn.net/liboyang71/article/details/76100170
springboot(4) 整合mybatis和hibernate 请删除项目中本地仓库的配置,或者改成国内的公共仓库,否则将无法启动
NULL 博文链接:https://selvemen.iteye.com/blog/457225
springboot+hibernate通过maven创建通过jpa实现的demo小实例
JAVA的hibernate手动获取session的方法