springboot,hibernate,exception no session 问题解决
2018-02-07 00:00
1576 查看
异常: could not initialize proxy - no Session;
解决方法:
1.
2.
3.
4.
个人主页:http://knight-black-bob.iteye.com/
谢谢您的赞助,我会做的更好!
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/
谢谢您的赞助,我会做的更好!
相关文章推荐
- Spring Boot之No session repository could be auto-configured, check your configuration问题解决
- SSH - org.hibernate.LazyInitializationException: could not initialize proxy - no Session问题解决办法
- 解决org.hibernate.LazyInitializationException: could not initialize proxy - no Session懒载入问题
- 解决org.hibernate.LazyInitializationException: could not initialize proxy - no Session问题
- 使用clone解决hibernate+spring集成中的延迟加载问题及分析(no session or session was closed)
- 解决spring+springMVC+Hibernate+spring-data-jpa懒加载No session问题
- 解决org.hibernate.LazyInitializationException: could not initialize proxy - no Session懒加载问题
- 使用clone解决hibernate+spring集成中的延迟加载问题及分析(no session or session was closed)
- SpringMVC3+Hibernate4问题:org.hibernate.HibernateException: No Session found for current thread
- 《Springboot极简教程》问题解决:Springboot启动报错 Whitelabel Error Page: This application has no explicit mapping for
- spring boot之解决懒加载session was closed问题
- 解决org.apache.shiro.session.UnknownSessionException: There is no session with id的问题(转)
- 关于在Spring中Hibernate的No Session found for current thread问题
- 添加@Transactional ------spring boot中session中断的问题及其解决
- 解决一个Sping管理hibernate时的事务问题(No Hibernate Session bound to thread)
- 解决 Springboot Unable to build Hibernate SessionFactory @Column命名不起作用
- Spring+hibernate中的问题解决:java.lang.ClassCastException: $Proxy6 cannot be cast to com.mqEsb.service.imp
- 解决了Hibernate+Spring+Struts架构使用OpenSessionInView的问题
- 解决Hiberante延迟加载问题——could not initialize proxy - no Session & 简介Hibernate的持久化
- Spring使用OpenSessionInViewFilter解决Hibernate的lazy延时加载问题