You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring R2DBC与jOOQ集成时事务回滚失效问题求助

Spring R2DBC + jOOQ 事务回滚失效问题

问题现象

基于Spring R2DBC与jOOQ开发时,遇到事务回滚失效的异常情况:事务内执行两次插入操作,第二次插入抛出异常后,日志显示ROLLBACK语句已执行,但第一次插入的记录并未被回滚;将jOOQ的DSLContext替换为DatabaseClient实现插入逻辑后,事务回滚恢复正常,推测问题源于jOOQ的R2DBC适配逻辑。

代码示例

DemoRepository 实现

suspend fun insert(id: String) {
    if (id == "b") {
        throw RuntimeException("error while inserting")
    }

    db.insertInto(DEMO_TABLE)
        .set(DEMO_TABLE.ID, id)
        .awaitSingle()
}

DemoService 事务逻辑

suspend fun addRecords(): Unit = transactionalOperator.executeAndAwait {
    log.info("Inserting records")
    repo.insert("a")
    repo.insert("b")  // 此处抛出异常
}

实际表现

执行addRecords()后调用repo.getAll(),返回结果为["a"],而非预期的空列表[]。

内容的提问来源于stack exchange,提问作者memoryfoam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 03:22:33