JPA: pattern for handling OptimisticLockException

后端 未结 4 1509
隐瞒了意图╮
隐瞒了意图╮ 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条回答
  •  天涯浪人
    2020-12-14 08:54

    If you get an optimistic locking exception, it means that some other transaction has committed changes to entities you were trying to update/delete. Since the other transaction has committed, retrying immediately might have a good chance to succeed.

    I would also make the method fail after N attempts, rather than waiting for a StackOverflowException to happen.

提交回复
热议问题