This illustration shows the interaction amongst the objects used when you use a Unit of Work in a JTA environment when an external transaction already exists. The Application calls the Session method getActiveUnitOfWork. The Unit of Work calls the Container and associates itself with the External Transaction. The Session returns a non-null Unit of Work to the Application. The Application uses the Unit of Work but does not call commit. The Container decides when a commit is necessary at which time the Container calls the Unit of Work call-back method beforeCompletion. The Unit of Work then writes its SQL to the database. When the commit ends (either successfully or not), the Container calls the Unit of Work call-back method afterCompletion, passing in a boolean result parameter. The Unit of Work examines the result. If the result is true, the commit was successful and the Unit of Work merges changes to the Session cache. If the result is false, the commit was unsuccessful and the Unit of Work does not merge changes to the Session cache.