美文网首页
2018-09-12 spring中的懒加载与事务--排坑记录

2018-09-12 spring中的懒加载与事务--排坑记录

作者: sickle4j | 来源:发表于2018-09-12 17:00 被阅读0次

    在使用Spring JPA时出现

                org.hibernate.LazyInitializationException: could not initialize proxy [xxxx#18] - no Session

    尝试1:  在Service方法中新增了@Transactional进行事务添加

    尝试2: 在@OneToMany的方法上,使用@Lazy(false)

    尝试3: 在@OneToMany的参数中使用fetch=FetchType=Eager


    尝试4: 在application.properties的配置文件中新增spring.jpa.open-in-view=true

    启动类中注入OpenEntityManagerInViewFilter

    @Bean

    publicOpenEntityManagerInViewFilteropenEntityManagerInViewFilter(){

    returnnewOpenEntityManagerInViewFilter();

    }

    尝试5 :  spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true

    相关文章

      网友评论

          本文标题:2018-09-12 spring中的懒加载与事务--排坑记录

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