When does @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) commit?

SDReyes picture SDReyes · Jul 23, 2012 · Viewed 41.7k times · Source

An EJB method named Aby calls another EJB method named Bob

Bob is marked with @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

When does bob transaction commits?:

a) when bob invocation ends

b) when aby invocation ends

c) other. when?

Answer

Petr Mensik picture Petr Mensik · Jul 23, 2012

I think A is right. When the method Bob is being called, it creates new transaction for it and method Aby gets suspended until the Bob transaction is committed.

Also note that it has to be method from some other bean to make it transactional, methods called from the same bean do not act as a business methods.

See this great article for further explanation.