Previous Contents Index DocHome Next |
iPlanet Application Server Developer's Guide (Java) |
Chapter 7 Handling Transactions with EJBs
This chapter describes the transaction support built-in to the EJB programming model. This chapter begins by introducing the EJB transaction model, and explains container and bean managed transactions. This chapter provides the semantics of all transaction attributes and use of the Java Transaction API for bean managed transactions. Finally, it discusses the restrictions on various combinations of EJB types and transaction attributes.This chapter contains the following sections:
Understanding the Transaction Model
Understanding the Transaction Model
One primary EJB advantage is the support they provide for declarative transactions. In the declarative transaction model, attributes are associated with beans at deployment time. Its the container's responsibility based on the attribute value, to demarcate and transparently propagate transactional context. The container is also responsible, in conjunction with a transaction manager, for ensuring all participants in the transaction see a consistent outcome.Declarative transactions free the programmer from explicitly demarcating transactions. They facilitate component-based applications where multiple components, potentially distributed and updating heterogeneous resources, can participate in a single transaction. The EJB specification also supports programmer demarcated transactions using javax.transactions.UserTransaction().
Its necessary to understand the distinction between global and local transactions in order to understand the iPlanet Application Server support for transactions. Global transactions are managed and coordinated by a transaction manager, and can span multiple databases and processes. The transaction manager typically uses the XA protocol to interact with the Enterprise Information System (EIS) database. Local transactions are native to a database and are restricted within a single process. Local transactions work against a single EIS only. Local transactions are typically demarcated using JDBC APIs. In an iPlanet Application Server, the container or javax.transaction.UserTransaction() starts all transactions.
The EJB specification requires support for flat (as opposed to nested) transactions. In this model each transaction is decoupled from and independent of other transactions in the system. Flat transactions are by far the most prevalent model and are supported by most commercial database systems.
Specifying Transaction Attributes in an EJB
Transactional attributes are specified on a bean wide basis or on a per method basis for a bean's remote interface. If both levels specify attributes, method specific values take precedence over bean wide values. These two should be mixed with care since some combinations are invalid as documented in the restrictions section.Transactional attributes are specified as part of the bean's XML DD file. For more information, see "EJB iPlanet Application Server XML DTD."
Using Bean Managed Transactions
While its preferable to use container managed transactions, your application requirements may necessitate using bean managed transactions. For more information on managing transactions programmatically, see the Enterprise JavaBeans Specification, v1.1 for this interface at the following URL:http://java.sun.com/products/ejb/javadoc-1.1/javax/ejb/EJBContext.html
Previous Contents Index DocHome Next
Copyright © 2001 Sun Microsystems, Inc. Some preexisting portions Copyright © 2001 Netscape Communications Corp. All rights reserved.
Last Updated June 14, 2001