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)
问题解决。