Skip Headers

# Using a Unit of Work When an External Transaction Exists

Previous

Next

When `getActiveUnitOfWork` returns a unit of work that is not `null`, you are associated with an existing external transaction. Use the unit of work as usual.

As the external transaction was not started by the unit of work, issuing a `commit` on it will not cause the external transaction to be committed. The unit of work will defer to the application or container that began the transaction. When the external transaction does get committed by the container, TopLink receives synchronization callbacks at key points during the commit transaction.

The unit of work sends the required SQL to the database when it receives the `beforeCompletion` callback.

The unit of work uses the `Boolean` argument received from the `afterCompletion` callback to determine if the commit was successful (`true`) or not (`false`).

If the commit transaction was successful, the unit of work merges changes to the session cache. If the commit transaction was unsuccessful, the unit of work discards the changes.

Figure: Unit of Work When an External Transaction Exists shows the life cycle of a unit of work when an external transaction exists.

Unit of Work When an External Transaction Exists

Description of "Unit of Work When an External Transaction Exists"