org.hibernate.LazyInitializationException: failed to lazily initialize a collection of 。。
程序员文章站
2022-03-02 13:26:06
...
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.southgis.ibase.organization.entity.OrganInfo.children, could not initialize proxy - no Session
用springboot方式运行单元测试时报错,实体中有多对一的懒加载字段。
解决方案:
1.application.yml配置文件中增加
spring:
jpa:
open-in-view: true
没有解决问题。
2.application.yml配置文件中增加
spring:
jpa:
properties:
hibernate:
enable-lazy-load-no-trans: true
没有解决问题。
3.测试方法上加注解 @Transactional
(org.springframework.transaction.annotation.Transactional)
问题解决。
上一篇: Python实现抖音视频去水印
推荐阅读
-
java 解决实体类序列化时,报failed to lazily initialize 的问题
-
解决问题:failed to lazily initialize a collection of role异常解决
-
JPA中failed to lazily initialize a collection of role:‘xxxx‘ no session or session was closed异常!
-
org.apache.struts2.json.JSONException: org.hibernate.LazyInitializationException: failed to lazily i
-
OneToMany字段序列化 failed to lazily initialize a collection of role
-
failed to lazily initialize a collection of role: , could not initialize proxy - no Session
-
Hibernate 延迟加载的错误 failed to lazily initialize a collection of role
-
failed to lazily initialize a collection of role
-
failed to lazily initialize a collection of role 异常
-
failed to lazily initialize a collection of role 的问题