This lesson introduces you to distributed transactions.
In the first course in this series you programmed session beans. However, the course ignored transactions.
In most industrial-strength applications based on EJBs, transactions are used to ensure data integrity.
It is important that you understand how they work within the EJB architecture and that you know how to write beans that use them.
JTS and JTA
You will be introduced to the two Java packages, Java Transaction Services (JTS) and the Java Transaction API (JTA).
JTS is the underlying architecture that supports distributed transactions and JTA is the programmers' API used to access the services.
You will be introduced to the three different ways a transaction can be managed. They are:
Client-managed transactions--the client begins and commits the transaction
Bean-managed transactions- the bean starts and controls the transaction
Container-managed transactions-the EJB knows nothing about the transaction that the container is managing for it
Session beans can be involved in transactions.
If they are container-managed, the session bean may still have a need to know or affect the outcome of a transaction.
The SessionSynchronization object allows that session bean access to the transaction.
The final part of this module covers the exceptions that may be thrown by, and caught from, the transaction service.
Managing transactions can be difficult. This information will make it easy for you to write programs that work correctly, no matter what happens to your transaction.
Distributed Multitiered Applications
The Java EE platform uses a distributed multitiered application model for enterprise applications. Application logic is divided into components according to function, and
the application components that make up a Java EE application are installed on various machines depending on the tier in the multitiered Java EE environment to
which the application component belongs.
Figure 2.1 shows two multitiered Java EE applications divided into the tiers described in the following list. The Java EE application parts shown in Figure 2.1 are presented
in Java EE Components.
Client-tier components run on the client machine.
Web-tier components run on the Java EE server.
Business-tier components run on the Java EE server.
Enterprise information system (EIS)-tier software runs on the EIS server.
Although a Java EE application can consist of all tiers shown in Figure 2.1, Java EE multitiered applications are generally considered to be three-tiered applications
because they are distributed over three locations: client machines, the Java EE server machine, and the database or legacy machines at the back end. Three-tiered
applications that run in this way extend the standard two-tiered client-and-server model by placing a multithreaded application server between the client application
and back-end storage.