JPA: OptimisticLockException and Cascading

前端 未结 2 2124
刺人心
刺人心 2021-02-10 23:03

In my current project I use Spring Data JPA with Hibernate but consider this as a more general question that should also cover \"plain\" JPA.

I\'m uncertain how I should

2条回答
  •  南笙
    南笙 (楼主)
    2021-02-10 23:29

    The whole point of optimistic locking is to be able to tell the end user: Hey, you tried to save this important piece of information, but someone else saved it behind your back, so you'd better refresh the information, decide if you still want to save it and potentially enter some new values, and then retry.

    Just like with SVN, if you try to commit a file and someone else committed a new version before, SVN forces you to update your working copy and resole potential conflicts.

    So I would do the same as what JPA does : it lets the caller decide what to do by throwing the exception. This exception should be handled in the presentation layer.

提交回复
热议问题