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/


springboot,hibernate,exception no session 问题解决_第1张图片springboot,hibernate,exception no session 问题解决_第2张图片springboot,hibernate,exception no session 问题解决_第3张图片
 
 
 谢谢您的赞助,我会做的更好!

 

 

你可能感兴趣的:(springboot,hibernate,exception,no,session)