1
0
mirror of synced 2025-01-18 06:21:40 +03:00

[DDC-2757] Update documentation with regard to manually closing the EntityManager when an Exception occurs.

This commit is contained in:
Benjamin Eberlei 2013-10-26 12:32:53 +02:00
parent cedcac225f
commit 514dd4e852

View File

@ -70,7 +70,6 @@ looks like this:
$em->getConnection()->commit(); $em->getConnection()->commit();
} catch (Exception $e) { } catch (Exception $e) {
$em->getConnection()->rollback(); $em->getConnection()->rollback();
$em->close();
throw $e; throw $e;
} }
@ -81,14 +80,12 @@ require an active transaction. Such methods will throw a
``TransactionRequiredException`` to inform you of that ``TransactionRequiredException`` to inform you of that
requirement. requirement.
A more convenient alternative for explicit transaction demarcation A more convenient alternative for explicit transaction demarcation is the use
is the use of provided control abstractions in the form of of provided control abstractions in the form of
``Connection#transactional($func)`` and ``Connection#transactional($func)`` and ``EntityManager#transactional($func)``.
``EntityManager#transactional($func)``. When used, these control When used, these control abstractions ensure that you never forget to rollback
abstractions ensure that you never forget to rollback the the transaction, in addition to the obvious code reduction. An example that is
transaction or close the ``EntityManager``, apart from the obvious functionally equivalent to the previously shown code looks as follows:
code reduction. An example that is functionally equivalent to the
previously shown code looks as follows:
.. code-block:: php .. code-block:: php
@ -104,8 +101,8 @@ previously shown code looks as follows:
The difference between ``Connection#transactional($func)`` and The difference between ``Connection#transactional($func)`` and
``EntityManager#transactional($func)`` is that the latter ``EntityManager#transactional($func)`` is that the latter
abstraction flushes the ``EntityManager`` prior to transaction abstraction flushes the ``EntityManager`` prior to transaction
commit and also closes the ``EntityManager`` properly when an commit and rolls back the transaction when an
exception occurs (in addition to rolling back the transaction). exception occurs.
Exception Handling Exception Handling
~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~