【问题标题】:How do I keep Hibernate transaction opened in SpringBoot/GraphQL without using JPA?如何在不使用 JPA 的情况下保持在 SpringBoot/GraphQL 中打开的 Hibernate 事务?
【发布时间】:2019-12-29 18:34:23
【问题描述】:

我正在使用 GraphQL 来重建我的 REST 应用程序。 我遇到的问题之一是 GraphQLResolver 没有重用 GraphQLQueryResolver 中使用的事务。

我知道使用 JPA 和 OpenEntityManagerInViewFilter 会有所帮助,但现在还不能使用 JPA/EntityManager 重写数千个 DAO 来替换 Hibernate Session。

是否有替代方法可以使用“org.springframework.orm.hibernate5.LocalSessionFactoryBean”并仍然为 GraphQLResolver 保持事务打开?

@Component
@Transactional
public class CountryQuery implements GraphQLQueryResolver {

    public List<Country> countries() {
        ...
    }
}

@Component
@Transactional
public class CountryResolver implements GraphQLResolver<Country> {
  public List<Locale> locales(Country country) {
     ...
  }
}

【问题讨论】:

    标签: hibernate graphql-java


    【解决方案1】:

    我发现 AsyncTransactionalExecutionStrategy 在这篇文章中有效

    LazyInitializationException with graphql-spring

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-21
      • 2019-08-19
      • 2022-07-27
      • 1970-01-01
      • 1970-01-01
      • 2019-08-03
      • 2012-08-22
      • 2021-11-07
      相关资源
      最近更新 更多