Skip to content


DBAL-873: [GH-571] Introduced a Transaction object #2113

doctrinebot opened this Issue · 1 comment

3 participants


Jira issue originally created by user @doctrinebot:

This issue is created automatically through a Github pull request on behalf of BenMorel:

Url: #571


This is a first draft on the idea of a Transaction object, as suggested by @guilhermeblanco and @beberlei in doctrine/doctrine2#949.

This makes the following changes to Connection:

  • Adds the following methods:
    • createTransaction() : begins a transaction and returns the associated Transaction object
    • getTransactionManager() : returns the TransactionManager
  • Deprecates beginTransaction() in favour of createTransaction()
  • Deprecates the following methods, in favour of their counterparts on Transaction:
    • commit()
    • rollBack()
    • setRollbackOnly()
    • isRollbackOnly()
  • Deprecates the following methods, in favour of their counterparts on TransactionManager:
    • isTransactionActive()
    • getTransactionNestingLevel()
    • setNestTransactionsWithSavepoints()
    • getNestTransactionsWithSavepoints()

The new way of dealing with transactions is then:

$transaction = $connection->createTransaction();

It also automatically propagates commit() and rollback() to nested transactions:

$transaction1 = $connection->createTransaction();
$transaction2 = $connection->createTransaction();
$transaction1->commit(); // will commit $transaction2 then $transaction1

Overall, it's not a complicated change, does not introduce any BC break, and passes all existing tests.

I'm looking forward to hearing what you think!


Comment created by @doctrinebot:

A related Github Pull-Request [GH-571] was closed:

@doctrinebot doctrinebot added the Bug label
@beberlei beberlei was assigned by doctrinebot
@deeky666 deeky666 added New Feature and removed Bug labels
@beberlei beberlei was unassigned by deeky666
@deeky666 deeky666 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.