禁用 Spring Boot 2 Autocommit Hikari

Disabling Spring Boot 2 Autocommit Hikari

提问人:venkat 提问时间:12/29/2022 最后编辑:Tonivenkat 更新时间:12/31/2022 访问量:545

问:

我正在使用带有 JPA 休眠的 hikari 连接池。我想在与数据库交互时在读取操作期间禁用自动提交功能。

添加了属性。添加此属性后,在启动过程中出现以下错误。spring.datasource.hikari.auto-commit=falseapplication.properties

***************************
APPLICATION FAILED TO START
***************************

Description:

Binding to target HikariDataSource (HikariPool-1) failed:

    Property: spring.datasource.hikari.autoCommit
    Value: false
    Reason: Property 'autoCommit' threw exception; nested exception is java.lang.IllegalStateException: The configuration of the pool is sealed once started. Use HikariConfigMXBean for runtime changes.


Action:

Update your application's configuration

光版本:3.2.0

Springboot版本:1.5.14-RELEASE

spring-boot hikaricp 自动提交

评论


答:

0赞 times29 12/29/2022 #1

尝试添加以下 Hibernate 配置:

spring:
  jpa:
    properties:
      hibernate:
        connection:
          provider_disables_autocommit: true

有关此设置的更多信息,请参阅 Vlad Mihalcea 的博客

评论

0赞 venkat 12/29/2022
由于我使用的是spring boot 1.5.14.Release,因此休眠版本为5.0.12。我从您的博客中可以看出,从 Hibernate 5.2.10 开始,只有该属性适用。休眠 5.0.12 版本有没有其他选择?
0赞 times29 12/29/2022
@venkat这很不幸,对不起!更新依赖项版本是否没有选择?我不知道旧 Hibernate 版本的方法。
0赞 venkat 1/18/2023
我已经升级到 hibernate 5.4.12,并在 application.properties 中添加了属性 spring.jpa.properties.hibernate.connection.provider_disables_autocommit=true。但是在休眠日志中,我仍然看到 [ XNIO-1 task-1] o.h.e.t.internal.TransactionImpl : committing