An EJB method named Aby
calls another EJB method named Bob
Bob
is marked with @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
bob
transaction commits?:a) when bob
invocation ends
b) when aby
invocation ends
c) other. when?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With