Transaction Timeout Propagation Issue

Posted on

Hi all,

I have a case in which a bean has a timeout defined but it seems to be ignored or not effective. Similar posts suggest to use the annotation

org.jboss.ejb3.annotation.TransactionTimeout;

which is not the case here as I'm using it. I believe at some point the definition is ignored or overwritten, but don't know why.

A simplified design of my application is shown below (assume a transaction is created by MyBean.transactionalMethodA):

@Stateless
public class MyBean{
    @EJB
    private AnotherBean anotherBean;

    **@TransactionTimeout(value = 120, unit = TimeUnit.MINUTES)**
    public void transactionalMethodA(){
        ...
        anotherBean.transactionalMethodB();
    }
}

@Stateful
@Local
public class AnotherBean {

    @EJB
    private YetAnotherBean yetAnotherBean;

    **@TransactionAttribute(TransactionAttributeType.REQUIRED)**
    public void loadRows(){
        ...
        yetAnotherBean.load();
    }        
}

@Stateless
@Local
public class YetAnotherBean {

    @PersistenceContext
    private EntityManager em;

    @Override
    **@Asynchronous**
    public Future<Row> load() {
        new AsyncResult<>(em.createQuery(...).getResultList()); 
//-> Here a timeout is raised after 1 minute
    }        
}

Does the asynchronous call impact the timeout definition? I see the transaction being properly propagated, which would make it under the scope of 120 Minutes timeout.

How can I improve this design in order to avoid such unexpected timeouts?