美文网首页
spring boot hibernate 懒加载解决方案

spring boot hibernate 懒加载解决方案

作者: 码农 | 来源:发表于2016-08-05 18:00 被阅读3741次

spring boot 是快速构建微服务的新框架。
对于数据访问问题可以直接使用jpa技术,但是在单元测试发现spring jpa存在hibernate懒加载问题。

hibernate懒加载异常
但是spring-boot没有xml配置文件所以现在网络上好多的解决方案并不能适用在spring boot框架中。在遇到该问题苦苦查询后终于无意中发现了解决方案。
Spring application using JPA with Hibernate, lazy-loading issue in unit test
英文不好没有细看,但是可以看到在spring-boot项目中如何通过application设置hibernate的配置选项。
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true

spring.jap.properties后面可以接hibernate的各种配置,然后陪孩子会被自动注入的hibernate实例中。
然后再次运行单元测试全部通过,不在出现懒加载异常。

测试通过

相关文章

网友评论

      本文标题:spring boot hibernate 懒加载解决方案

      本文链接:https://www.haomeiwen.com/subject/zrzhsttx.html