JPA: pattern for handling OptimisticLockException

后端 未结 4 1512
隐瞒了意图╮
隐瞒了意图╮ 2020-12-14 08:33

what is the correct pattern for handling OLE in a (REST) web service? this is what i\'m doing now, for example,

protected void doDelete(HttpServletRequest re         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 08:46

    The "politically correct" answer in rest, is to return an HTTP 409 (Conflict) witch matches perfectly with the idea of optimistic locking. Your client should manage it, probably by retring a few seconds later.

    I wouldn't add the logic to retry in your app, as your client will already handle situations when you return a 40X code.

提交回复
热议问题