Nested Transactions

Home > Object Persistency API > API Reference > Nested Transactions

As described in the previous chapter there is a begin method within the TXContext interface that allows for creating nested transactions.

Database interactions are always executed in the context of a transaction, i.e. main transactions are automatically started. Therefore the begin method has the sole purpose of starting a nested transaction. A subsequent call to commit or rollback will not commit or rollback the main transaction but only the nested transaction.

Hence you can rollback to certain savepoints within your transactional context. Please note that you can start a nested transaction within a nested transaction as well.

Here's a simple example that shows the interaction with the TXContext interface when using nested transactions.

  1. insert - create an object; the main transaction has been automatically started.
  2. begin - start nested transaction 1.
    1. insert - create an object.
    2. begin - started nested transaction 2.
      1. update - change an object.
      2. rollback - rollback nested transaction 2.
    3. commit - commit nested transaction 1.
  3. update - update an object.
  4. commit - commit the main transaction.
  5. ...

Next chapter: Events

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.