Answer the question
In order to leave comments, you need to log in
What causes The EntityManager is closed error?
I use ORM Doctrine 2 in my project. There is an entity, I'm trying to add a record to the database trace. way:
$entity = new SomeEntity;
$entity->setCreated(new \DateTime())
->setSomeField(...);
$this->em->persist($entity);
$this->em->flush($entity);
Answer the question
In order to leave comments, you need to log in
And what is the result of execution $this->em->isOpen();
before adding a new entity? If false, then an error occurred somewhere before.
Are prePersist, postPersist events handled? The error may be there, especially if flush is called again in them.
EntityManager closes itself on any ORM-related error, for example, if the database request is incorrect, this is a big problem in projects where PHP process daemonization is used. If your application is based on PSR-15 and PHP-DI, you can keep the EntityManager always open using the following middleware:
https://github.com/autorusltd/doctrine-persistent-...
In any case, even if it's not yours stack, you can at least figure out how to reopen it. But most importantly, control errors in your application, do not complicate it, try to write in such a way that work with the database occurs only in endpoints (repositories that are called in endpoints), and not spread over the project...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question