Saturday, March 14, 2009

Why would a client application use JTA transactions (JTA)

Question :Why would a client application use JTA transactions? (JTA)

Answer :One possible example would be a scenario in which a client needs to
employ two (or more) session beans, where each session bean is deployed
on a different EJB server and each bean performs operations against
external resources (for example, a database) and/or is managing one or
more entity beans. In this scenario, the client's logic could required an allor-
nothing guarantee for the operations performed by the session beans;
hence, the session bean usage could be bundled together with a JTA
UserTransaction object.
In the previous scenario, however, the client application developer should
address the question of whether or not it would be better to encapsulate
these operations in yet another session bean, and allow the session bean to
handle the transactions via the EJB container. In general, lightweight clients
are easier to maintain than heavyweight clients. Also, EJB environments are
ideally suited for transaction management.
Context c = new InitialContext(); UserTransaction ut =
(UserTransaction) c.lookup("java:comp/UserTransaction");
ut.begin(); // perform multiple operations...

No comments: