Docs: EntityManager::transactional vs Connection::transactional #6095

Open
opened 2026-01-22 15:26:42 +01:00 by admin · 1 comment
Owner

Originally created by @ghost on GitHub (Nov 1, 2018).

https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/transactions-and-concurrency.html#approach-2-explicitly in "Approach 2: Explicitly" the first way (with beginTransaction()) when catching the exception does not close the entity manager, whereas the second way (with transactional(), see \Doctrine\ORM\EntityManager::transactional) does close the entity manager when an exception occurs. So these two peaces of code are not equivalent as stated. I think it should be $em->getConnection()->transactional() (which does not close the EntityManager) instead of $em->transactional().

Originally created by @ghost on GitHub (Nov 1, 2018). https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/transactions-and-concurrency.html#approach-2-explicitly in "Approach 2: Explicitly" the first way (with beginTransaction()) when catching the exception does not close the entity manager, whereas the second way (with transactional(), see \Doctrine\ORM\EntityManager::transactional) does close the entity manager when an exception occurs. So these two peaces of code are not equivalent as stated. I think it should be $em->getConnection()->transactional() (which does not close the EntityManager) instead of $em->transactional().
Author
Owner

@anilex commented on GitHub (Apr 7, 2020):

There is a reason for resetting the EM.

"...because Doctrine EntityManager becomes totally unusable when a Doctrine exception has been raised."

Here is a more detailed explanation.

@anilex commented on GitHub (Apr 7, 2020): There is a reason for resetting the EM. > "...because Doctrine EntityManager becomes totally unusable when a Doctrine exception has been raised." [Here](https://medium.com/lebouchondigital/thread-safe-business-logic-with-doctrine-f09c633f6554) is a more detailed explanation.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6095