Page 1 of 1

About Question enthuware.oce-jpad.v6.2.392 :

Posted: Sun Aug 30, 2015 1:09 pm
by romsky
I do not understand the explanation for 5th varian.
==
Since the question specifies that anotherBean.anotherMethod() executes in the same transaction that is started by myMethod(), anotherBean must be a CMT bean because if it were a BMT bean, the transaction started by myMethod() would have been suspended.
==

What is wrong if the transaction started by myMethod() would have been suspended?
If it is suspended, anotherMethod could not rollback it.

Re: About Question enthuware.oce-jpad.v6.2.392 :

Posted: Sun Aug 30, 2015 8:21 pm
by admin
The problem statement states that the second bean's method executes in the same transaction as the first bean. BMT will not satisfy this part of the problem.

Re: About Question enthuware.oce-jpad.v6.2.392 :

Posted: Thu Sep 20, 2018 8:12 pm
by __JJ__
Since the question specifies that anotherBean.anotherMethod() executes in the same transaction that is started by myMethod(), anotherBean must be a CMT bean because if it were a BMT bean, the transaction started by myMethod() would have been suspended.
How would it (the method in BMT bean anotherMethod) have been suspended? I thought that transactions are suspended by the use of

Code: Select all

@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
and that

Code: Select all

@TransactionAttribute
could only be used in CMT beans:
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.
Thanks.

Re: About Question enthuware.oce-jpad.v6.2.392 :

Posted: Thu Sep 20, 2018 8:40 pm
by admin
As per section 13.6.1 of EJB 3.1 Specification:
The container must manage client invocations to an enterprise bean instance with bean-managed transaction demarcation as follows. When a client invokes a business method via one of the enterprise bean’s client views, the container suspends any transaction that may be associated with the client request.
In the situation given in the question, if the given code calls anotherBean used BMT, the transaction started by this code would have to be suspended.

Re: About Question enthuware.oce-jpad.v6.2.392 :

Posted: Thu Sep 20, 2018 11:56 pm
by __JJ__
I've just seen this in ProJPA2 which confirms what you're saying:
One penalty of transactions being managed by the application instead of by the container is that they do not get propagated to methods called on another BMT bean. For example, if Bean A begins a transaction and then calls Bean B, which is using bean-managed transactions, then the transaction will not get propagated to the method in Bean B. Any time a transaction is active when a BMT method is invoked, the active transaction will be suspended until control returns to the calling method.
I think what I need to get my head around is that managing transactions in BMT is not as analagous to managing transactions in Java SE with EntityManager as I have been thinking it was. There is still "container stuff" going on, like here. A transaction is suspended, but not because an annotation was specified, nor because you called some txsuspend() method or other; it's just suspended, because, well, that's just how it works.

Thanks.