DDC-3363: "The EntityManager is closed." after insert error. #4160

Closed
opened 2026-01-22 14:36:21 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Oct 25, 2014).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user xawiers:

               try {
                    $em = $this->getContainer()->get('doctrine')->getManager();
                    $em->persist($article);
                    $em->flush();
                } catch (\Exception $e) {
                    $output->writeln($e->getMessage());
                }

If flush will generate error - all other flush operations will end with error: "The EntityManager is closed.".

Internet says that recreating EM is almost imposible without using own EM management code.

WHY i have to code EM management code to use EM? It's Doctrine's task to manage EM.

I just want to use try catch and process errors - Closing and opening connections it's Doctrine's task.

This task (reopen connection) should be done by Doctrine.

Originally created by @doctrinebot on GitHub (Oct 25, 2014). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user xawiers: ``` try { $em = $this->getContainer()->get('doctrine')->getManager(); $em->persist($article); $em->flush(); } catch (\Exception $e) { $output->writeln($e->getMessage()); } ``` If flush will generate error - all other flush operations will end with error: "The EntityManager is closed.". Internet says that recreating EM is almost imposible without using own EM management code. WHY i have to code EM management code to use EM? It's Doctrine's task to manage EM. I just want to use try catch and process errors - Closing and opening connections it's Doctrine's task. This task (reopen connection) should be done by Doctrine.
admin added the Bug label 2026-01-22 14:36:21 +01:00
admin closed this issue 2026-01-22 14:36:21 +01:00
Author
Owner

@doctrinebot commented on GitHub (Oct 25, 2014):

@doctrinebot commented on GitHub (Oct 25, 2014): - duplicates [DDC-1037: The EntityManager is closed when an exception is thrown in UoW's commit method](http://www.doctrine-project.org/jira/browse/DDC-1037)
Author
Owner

@doctrinebot commented on GitHub (Nov 5, 2014):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Nov 5, 2014): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4160