title: JPA Nested Transactions And Locking
body: <p>Consider the scenario two methods exists in different stateless bean</p>
  
  <pre><code>public class Bean_A {
     Bean_B beanB; // Injected or whatever
     public void methodA() {
      Entity e1 = // get from db
      e1.setName("Blah");
      entityManager.persist(e1);
      int age = beanB.methodB();
  
     }
  } 
  public class Bean_B {
    //Note transaction
    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
     public void methodB() {
  
      // complex calc to calculate age  
    }
  
  }
  </code></pre>
  
  <p>The transaction started by BeanA.methodA would be suspended and new transaction would be started in BeanB.methodB. What if the methodB needs to access same entity that was modified by methodA. This would result in deadlock.Is it possible to prevent it without relying on isolation levels?</p>