Reputation: 307
I have read about TransactionAttributeType.REQUIRED
that
If the client is running within a transaction and invokes the enterprise bean’s method, the method executes within the client’s transaction. If the client is not associated with a transaction, the container starts a new transaction before running the method.
The client is an EJB application deployed on server A, and invokes a method methodB
of another bean that is deployed on another server B within a transaction. If methodB
has TransactionAttributeType.REQUIRED
, then it'll run under the same transaction as started by the client application. Right?
If yes, then how does the application deployed on different server know about the transaction started on another server?
If no, then how does methodB
use the same transaction?
I am somewhat new to EJB so please go easy on me. Any pointer to the right direction will be highly appreciated.
Upvotes: 2
Views: 82
Reputation: 13008
If the client on server A has started a transaction, the transaction context is propagated into the bean annotated with TransactionAttributeType.REQUIRED
. It's part of the invocation.
So the answer to your first question is yes: methodB
in server B, called by the EJB application on server A, runs in the same transaction. The final commit
or rollback
is controlled by the client running on server A.
The client on server A may enlist other XA resources in the same transaction as well: For example, it writes to an XA data source and sends a message using XA JMS. Then the commit
on the transaction persists the changes caused by methodB
, it will write the row into the database, and the message is in the queue. If the client does a rollback
, all units of work are rolled back (and nothing has changed).
Related: Two-phase commit protocol (Wikipedia)
Upvotes: 1