JPA Nested Transactions And Locking

前端 未结 4 598
滥情空心
滥情空心 2021-02-01 06:34

Consider the scenario two methods exists in different stateless bean

public class Bean_A {
   Bean_B beanB; // Injected or whatever
   public void methodA() {
           


        
4条回答
  •  [愿得一人]
    2021-02-01 06:47

    Here is a recent article about the use of REQUIRES_NEW transaction demarcation.

    From my experience, there should be no dead-lock with standard code: queries with restrictive where clause and few inserts. In some specific cases, some database engine may do lock escalation if there is many rows read or inserted on a single table during the transaction... and in that case, yes a dead-lock may occur.

    But in that case, the problem does not come from REQUIRES_NEW but from SQL design. If that design cannot be improved, then you have no other choice to change isolation level to a more loose level.

提交回复
热议问题