Getting Started with Enterprise JavaBeans™

G

Entity Beans

Tutorial Home Section Home Previous Section Next

Get

Get

What Are Transactions?

     Transaction technology was developed primarily in the database arena, and a transaction generally means one or more statements that comprise a logical unit of work (known as an LUW). In this context, the term transaction is used to mean an all or nothing series of operations; that is, everything should complete successfully or nothing should, in which case all state should revert to the state that existed prior to the transaction start. The classic example of a transaction involves withdrawing money from one bank account and depositing it in another. If only the withdrawal completes, money is lost. Debits and credits in a double entry accounting system provide another example: both the debit and credit must complete, otherwise, it should appear that neither operation was attempted. Once a transaction begins, it continues until a commit (make the changes persistent) or a rollback (revert to the previous state) is issued.

     You should understand that transaction handlers only control the results on persistent data. If your application's variables change during the course of a transaction that is eventually rolled back, you will have to write your own code to revert those variables to the previous state.

     Transactions also allow concurrent, multiuser operations to appear as if they occurred serially. Isolation levels control the degree of concurrency and how transactions may affect each other. JDBC, the Java API for working with relational databases, defines the following isolation levels:

     A client normally may set the isolation level or use the default provided by the JDBC driver. It is important, however, to be aware that entity beans have some transactional restrictions:

     Other transactional systems may use different isolation levels or contexts. If the default level has to be changed to meet an application's requirements, the developer must write to APIs specific to the associated resource manager to accomplish the task (JDBC is a resource manager).

     EJB containers are required to support the Java Transaction API (JTA) and the Connector APIs, to provide flat transaction support for all types of beans (see Controlling Transactions). The container may, but is not required to, use a Java Transaction Service (JTS) implementation for propagating transactions across servers. JTS is a Java binding of the CORBA Object Transaction Service (OTS) 1.1 specification, which uses the IIOP protocol. Regardless of the specific transaction technology used, the actual transaction operations are mostly transparent to the EJB developer.

     For more information about transactions, JDBC, isolation levels, JTS, and JTA, see Chapter 17, "Support for Transactions", of the Enterprise JavaBean 2.0 specification, along with the other material in Resources.



Tutorial Home Section Home Previous Section Next