Optimistic locking in a RESTful application

后端 未结 2 997
隐瞒了意图╮
隐瞒了意图╮ 2020-12-31 17:09

At work, we\'re developing a RESTful application where the data layer will be handled by Hibernate. But we\'re not sure how to handle updates on entities.

We\'re pla

2条回答
  •  时光说笑
    2020-12-31 17:18

    Your strategy is good. Simply copy the version number coming from the client into the loaded entity (or use merge(), which will do the same), and when Hibernate flushes the entity, if the version number has been incremented, you'll have an optimistic lock exception.

    You don't need to check anything by yourself. Hibernate does the check for you.

提交回复
热议问题