【问题标题】:SpringBoot v2.7.0 - Select-Query without transactional-annotation => No transactional EntityManager available | now with github-exampleSpringBoot v2.7.0 - Select-Query without transactional-annotation => No transactional EntityManager available |现在使用 github-example
【发布时间】:2022-08-04 12:57:03
【问题描述】:

我目前正在开发一个较旧的 Spring 项目(不是 Spring Boot)。这使用 spring-boot-dependencies 作为父 BOM。计划在不久的将来迁移到 SpringBoot。我们目前仍在使用 2.6.7 版本的依赖项。我现在想升级到 2.7.0。

我在 JPA 存储库中自己的查询有问题。该查询是一个只执行一个选择的 JPQL 查询: @Query(\"select x from y where y.date = (select max(tmp.date) from y tmp where y.thingId = tmp.thingId)\")

运行查询时,会抛出“No transactional EntityManager available”。如果我使用 Transactional-annotation 对存储库或方法进行注释,则查询运行。但是,令我惊讶的是,现在有必要这样做吗?以前,可以在没有事务注释的情况下执行查询。这里有变化吗?我在发行说明中找不到任何信息。


编辑:我创建了一个带有问题的抽象 github 项目:https://github.com/helo-trix/72520519

  • 您是否添加了另一个数据库连接?
  • 当我迁移到 spring boot 2.7.0 时,我遇到了同样的问题。我的项目中也有多个数据源。那么......多个DS,spring boot 2.7.0和实体管理器之间的联系是什么? Spring Boot 2.7.0 发生了什么?我的代码正在使用 2.6.7 。问候
  • 我只有一个DS。观看我对 github 示例的编辑。

标签: java spring spring-boot


【解决方案1】:

这是一个已在此处修复的错误https://github.com/spring-projects/spring-data-jpa/pull/2542

升级到 spring boot 2.7.2 将解决您的问题

【讨论】:

    猜你喜欢
    • 2014-10-09
    • 2018-04-12
    • 2020-08-21
    • 1970-01-01
    • 1970-01-01
    • 2015-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多