Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) commit?

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?

like image 236
SDReyes Avatar asked Jul 23 '12 14:07

SDReyes


People also ask

What is TransactionAttributeType Requires_new?

Today I would like to share my experience about the EJB TransactionAttributeType “REQUIRES_NEW”. The goal of this attribute is to isolate a method from the current transaction context and run the code in a new separate transaction.

What will happen if a transactional client invokes an enterprise bean method whose transaction attribute is set to never within a transaction context?

If the client is running within a transaction and invokes the enterprise bean's method, the container throws a RemoteException. If the client is not associated with a transaction, the container does not start a new transaction before running the method.

What is @TransactionAttribute?

The TransactionAttribute annotation specifies whether the container is to invoke a business method within a transaction context. The TransactionAttribute annotation can be used for session beans and message driven beans. It can only be specified if container managed transaction demarcation is used.


1 Answers

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.

like image 82
Petr Mensik Avatar answered Oct 10 '22 20:10

Petr Mensik