Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-2757

Manual transcation handling not possible when transaction fails, documentation gives wrong example


    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4
    • Fix Version/s: 2.5
    • Component/s: ORM
    • Security Level: All
    • Labels:


      The current version of documentation states in section:

      13.1.2. Approach 2: Explicitly

      that one can use a custom transaction handling. One of the described things is that one has a responsibility for closing the entity manager, after exception is thrown.

      However, the fact is that the unit of work will close itself regardless, so closing the EM is not up to the user (documentation is wrong there). In fact, there is no way, one can say: Don't close the entity manager, I know what I am doing, just clear the thing and let me continue somehow (which is another topic/feature).

      What is an issue however is that once you reset an entity manager/obtain a new one, the old objects fetched are not usable, even though one just needs some information from them (for example, their primary keys) so that a new object can be created. When I try using them, there is a PHP Notice that spl_object_hash of the given object cannot be found inside entityIdentifiers (line 2852, UnitOfWork.php), and merging previously selected entities into the new entity manager does not work for some reason – the entity stays in detached state. So the only possibility is to refetch all data. Which means, scenarios such as these:

      foreach ($data as $record) {
          // update the entity
          // persisting new $record fails, as some constraint gets violated (unique, for instance)
          // catch the exception, obtain new EM, continue

      ... won't work, or all highly problematic to say the least. I am not able to figure out, how to handle such scenarios properly using Doctrine. Just to make the scenario clear, there is no way I can check beforehand, that given constraint will be violated, short of complete exclusive table lock.


        baldman Tomas Plesek created issue -
        beberlei Benjamin Eberlei made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.5 [ 10522 ]
        Resolution Fixed [ 1 ]


          • Assignee:
            beberlei Benjamin Eberlei
            baldman Tomas Plesek
          • Votes:
            0 Vote for this issue
            2 Start watching this issue


            • Created: