LazyInitializationException with graphql-spring

前端 未结 6 1404
庸人自扰
庸人自扰 2020-12-31 04:21

I am currently in the middle of migrating my REST-Server to GraphQL (at least partly). Most of the work is done, but i stumbled upon this problem which i seem to be unable t

6条回答
  •  悲哀的现实
    2020-12-31 05:09

    My prefered solution is to have the transaction open until the Servlet sends its response. With this small code change your LazyLoad will work right:

    import javax.servlet.Filter;
    import org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter;
    
    @SpringBootApplication
    public class Application {
    
      public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
      }
    
      /**
       * Register the {@link OpenEntityManagerInViewFilter} so that the
       * GraphQL-Servlet can handle lazy loads during execution.
       *
       * @return
       */
      @Bean
      public Filter OpenFilter() {
        return new OpenEntityManagerInViewFilter();
      }
    
    }
    

提交回复
热议问题