如何有效解决Spring Boot与Hibernate懒加载冲突问题?
- 内容介绍
- 文章标签
- 相关推荐
本文共计562个文字,预计阅读时间需要3分钟。
Spring Boot是快速构建微服务的新框架。针对数据访问问题,可以直接使用JPA技术,但在单元测试中可能会发现Spring + JPA存在Hibernate懒加载问题。然而,Spring Boot没有XML配置文件,因此在网络上有很多相关资料。
spring boot 是快速构建微服务的新框架。
对于数据访问问题可以直接使用jpa技术,但是在单元测试发现spring jpa存在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实例中。
然后再次运行单元测试全部通过,不在出现懒加载异常。
本文共计562个文字,预计阅读时间需要3分钟。
Spring Boot是快速构建微服务的新框架。针对数据访问问题,可以直接使用JPA技术,但在单元测试中可能会发现Spring + JPA存在Hibernate懒加载问题。然而,Spring Boot没有XML配置文件,因此在网络上有很多相关资料。
spring boot 是快速构建微服务的新框架。
对于数据访问问题可以直接使用jpa技术,但是在单元测试发现spring jpa存在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实例中。
然后再次运行单元测试全部通过,不在出现懒加载异常。

