1
votes

We are having problems with table locking and deadlocks in EJB 3.0 / JPA 1.0 / DB2 10.1 application. We found out that if simple SELECT query is excecuted within ejb method that supports transaction, records are getting locked (next key share lock - NS lock mode), which eventually leads to potential problems with deadlocks. If same query is exeçuted within ejb method without transaction no locking occurs, which I think is the way it should be.

Question: we have ejb ejbA with methodA that requires transaction. We have ejbB with methodB which has simple select query, and should not run within transaction so we set trnasaction attribute to: NotSupported. We call methodB from methodA.

Oracle EE6 tutorial says: If the client is running within a transaction and invokes the enterprise bean’s method, the container suspends the client’s transaction before invoking the method. After the method has completed, the container resumes the client’s transaction.

As we understand methodB should suspend transaction from methodA and should not lock the record, but it does, which leads me to conclusion that transaction is not suspended.

Can you please help us resolve and understand the behavior.

1

1 Answers

0
votes

How do you call methodB ?

If the calling code looks like:

@Stateless
public class MyEJB{

    @TransactionAttribute(REQUIRED)
    public void methodA (){
       ...
       methodB();
       ...
    }

    @TransactionAttribute(NOT_SUPPORTED)
    public void methodB (){
        ...
    }
}

the application server will never know when to suspend the transaction (the method call does not invoke the container-created proxy's method).

To properly call a method with a different transaction semantic, you need to access the augmented object available on the SessionContext as in:

@Stateless
public class MyEJB{

    @Resource
    SessionContext sc;         

    MyEJB self;  

    @PostConstruct
    public void init(){
      this.self = this.sc.getBusinessObject(MyEJB.class);
    }

    @TransactionAttribute(REQUIRED)
    public void methodA (){
       ...
       self.methodB();
       ...
    }

    @TransactionAttribute(NOT_SUPPORTED)
    public void methodB (){
        ...
    }
}