Previous     Contents     Index     Next     
iPlanet Application Server Developer's Guide



Chapter 8   Handling Transactions with EJBs


This chapter describes the transaction support built-in to the EJB programming model. This chapter contains the following sections:



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. It is the container's responsibility, based on the attribute value, to demarcate and transparently propagate the transactional context. The container is also responsible, in conjunction with a transaction manager, for ensuring that 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. To obtain a UserTransaction object, you must perform a JNDI lookup.

It is 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) or database. Local transactions are native to a single EIS or database only and are restricted within a single process. Both local and global transactions are demarcated using the javax.transaction.UserTransaction interface, which the client must use, but internally local transactions are implemented with the JDBC API, which makes them faster than global transactions.

The iPlanet Application Server operates in either global or local transaction mode; you cannot mix global and local transactions.



Note If your application uses global transactions, configure and enable the corresponding iPlanet Application Server Resource Managers. For more information, see the Deployment Tool Online Help and the Administrator's Guide.



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. In a flat transaction, you cannot start another transaction in the same thread until the current transaction ends. Flat transactions are by far the most prevalent model and are supported by most commercial database systems. Nested transactions offer a finer granularity of control over transactions.



Note Third party drivers are not allowed to participate in transactions.





Specifying Transaction Attributes in an EJB



Transaction 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.

Transaction 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 it is 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

You can provide a pointer to a bean managed transaction. For example, if you start a transaction for a stateful session bean, the bean is not passivated (failover is affected: you see the state before the transaction). However, if you start a transaction for a stateless session bean, the transaction is rolled back once the method returns.


Previous     Contents     Index     Next     
Copyright © 2002 Sun Microsystems, Inc. All rights reserved.

Last Updated March 06, 2002