Jira issue originally created by user gediminasm:
Is there any particular reason why onFlush event is not triggered when the transaction is allready open? https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/UnitOfWork.php#L290 It would help a lot developing listeners since this event is the mostly used one and since theres preFlush now it seems a logical solution if onFlush would be a start of transaction in general
Comment created by @beberlei:
onFluish is not the start of a transaction. It has nothing to do with this.
Comment created by @ocramius:
Is a third event needed? Or is this to be marked as "won't fix"?
Maybe onBeginTransaction, onCommit and onRollback.
However since you can start transactions manually using $em->beginTransaction(), the Flush events are somehwat independent of transactions anyways.
Comment created by gediminasm:
Well, user can start transaction anytime, but the fact is that if we think ORM we do not know nothing about the database. we just persist and flush objects.
Yes I think these would be very useful, from how I see it, if you use event listeners, is:
loadClassMetadata: you can apply extra mapping
onFlush: you can modify entity changesets, or persist recalculate new ones, without triggering the database, since it is not used to begin the database modifications yet.
onBeginTransaction: could use the database modifications keeping in sync the entity changesets. the thing about this event is that usually in behavioral way atomic updates are required. for example nestedset tree sync lft rgt columns, sortable sync the sort index, materialized path, all these requires atomic updates, and the best place is the start of transaction.
onCommit: could be useful to execute right before commit, finalizing database modifications could be done.
onRollback: this one is really something, since if you go far, there might be something like files uploaded during the entity processing, and you may want to remove them if transaction fails.
Comment created by @guilhermeblanco:
This situation was barely documented here: http://www.doctrine-project.org/jira/browse/[DDC-1443](http://www.doctrine-project.org/jira/browse/DDC-1443)
We need a better Transaction API that completely fixes the computation of changesets and also allow more fine grained control over Entities and their corresponding information.
I'd postpone this one until 3.0.