springboot,hibernate,exception no session problem solving

 

 

异常: 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"])

 

Solution:

1.

JPA Hibernate disallows lazy loading

 

2.

Add configuration information to the properties file
spring.session.store-type=none

 

3.

Add the following configuration to application.properties:

spring.jpa.open-in-view=true

 

4.

@ManyToOne(fetch = FetchType.LAZY)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Donate to developers 

Driven by interest, I write 免费something with joy and sweat. I hope you like my work and can support it at the same time. Of course, if you have money to support a money field (support Alipay, WeChat, and the buckle group), if you have no money to support a personal field, thank you.

 

Personal homepage : http://knight-black-bob.iteye.com/



 
 
 Thank you for your sponsorship, I will do better!

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326422793&siteId=291194637