spring-data-jpa 插入触发器更新记录,获取jpa中的更新值

dvtswwa3  于 2022-11-10  发布在  Spring
关注(0)|答案(1)|浏览(241)

我 有 一 个 由 spring boot jpa 执行 的 插入 查询 。 插入 查询 触发 了 一 个 DB 触发 器 , 它 更新 了 一 个 列 slug 。 有 没有 办法 在 同一 个 jpa 事务 中 获取 更新 的 值 ( 而 不是 再次 从 DB 中 读取 记录 或 使用 存储 过程 ) ?
下面 的 代码 是 为 解决 问题 而 简化 的 。

@RestController
@RequestMapping(value = "user")
public class UserController {
    @PostMapping
    public Invite saveUser(@Validated @RequestBody User user) {
        // user.slug is null
        User newUser = userRepo.save(user);
        // DB insert
        // DB trigger has logic to update user.slug column in DB 
        // newUser.slug is null; in spite of DB having a value for the slug column
    }
}

中 的 每 一 个
注意 : 我 尝试 了 建议 的 here , 但 没有 成功 。

vkc1a9a2

vkc1a9a21#

我最终显式调用了entityManager.refresh()

相关问题