springboot,hibernate,exception no session 问题解决

 

 

异常: 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/



 
 
 谢谢您的赞助,我会做的更好!

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值