Distributed Transactions   «Prev  Next»
122
Lesson 3 Transactions and remote objects
ObjectiveTransactions and remote objects for Entity Beans

Transactions and Remote Objects for Entity Beans

Describe how transactions are applied to remote objects. Transactions can be applied to remote objects. However, in the first course in this series we discussed the benefits of separating business logic from plumbing. Thus, the bean instance is best kept in the dark about the transaction. The transaction will be managed by the container. Consider the SlideShow below in which we transfer the $100 from checking to savings in a remote object called Teller.

How Remote EJB Transactions are applied

1) In container: a message received from client for the transfer() method; begin transaction executed and the transfer method called.
1) In container: a message received from client for the transfer() method;
"begin transaction" executed and the transfer() method called.

2) In transfer() a request is made to deduct $100 from checking.
In transfer() a request is made to deduct $100 from checking.

3) Inside database, $100 is deducted from checking account temporarily.
Inside database, $100 is deducted from checking account temporarily.

4) In transfer() a request is made to credit $100 to savings
In transfer() a request is made to credit $100 to savings


5) In database, $100 is temporarily credited to savings account
In database, $100 is temporarily credited to savings account

6) In container, assuming all went well, commit transaction executed by the container
In container, assuming all went well, "commit transaction" executed by the container

7) Database commits credits and debits permanently
In database, database commits credits and debits permanently


  1. In container: a message received from client for the transfer() method;
  2. In transfer() a request is made to deduct $100 from checking.
  3. Inside database, $100 is deducted from checking account temporarily.
  4. In transfer() a request is made to credit $100 to savings
  5. In database, $100 is temporarily credited to savings account
  6. In container, assuming all went well, "commit transaction" executed by the container
  7. In database, database commits credits and debits permanently

Note that, in this case, the EJB does not have to know any of the details concerning the transaction. All it does is make individual requests to the database. It does not need to know that there is a transaction happening at all.
RMI-IIOP: Remote Method Invocation (RMI) allows you to invoke remote objects independently of the underlying protocol. The Java SE native RMI protocol is Java Remote Method Protocol (JRMP). RMI-IIOP is an extension of RMI used to integrate with CORBA. Java interface description language (IDL) allows Java EE application components to invoke external CORBA objects using the IIOP protocol. CORBA objects can be written in many languages (Ada, C, C++, Cobol, etc.) as well as Java. In the next lesson you will be introduced to the management of distributed transactions.

Using naming services to locate resources and leveraging remote object architectures are two ways in which you can enable network and mobility transparency in your application. The Java Naming and Directory Interface (JNDI) and Remote Method Invocation (RMI) support this type of transparency in J2EE. Your J2EE server provider usually provides location transparency as part of server clustering. As noted in the previous section, you must share responsibility for failure transparency with your server vendor.