Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对 JPA 持久性有疑问。我想更改特定列的值(例如 1 到 2),并进一步获取相应的行(列值为 2)。如果其他服务出现错误,我想将列值恢复为 1。
我们可以在 JPA 中做到这一点吗?
如果您使用 Spring Data JPA,请尝试以下操作:
@Transactional @Modifying @Query("UPDATE ...")
您可以对您的方法使用@Transactional 注释。因此,您可以将值从 1 更改为 2。然后获取相应的行。任何地方发生异常,它将恢复为 1。