Answer the question
In order to leave comments, you need to log in
Doctrine mark transactions as rollback?
The code:
$this->entityManager->beginTransaction();
$this->entityManager->persist($entityA);
$this->entityManager->flush();
...
$this->entityManager->rollback();
$this->entityManager->persist($entityB);
$this->entityManager->flush();
Transaction commit failed because the transaction has been marked for rollback only
Answer the question
In order to leave comments, you need to log in
After rollback, you can do this:
if (!$this->entityManager->isOpen()) {
$entityManager = $this->entityManager->create($this->entityManager->getConnection(), $this->entityManager->getConfiguration(), $this->entityManager->getEventManager());
$this->serviceManager->setAllowOverride(true);
$this->serviceManager->setService('entityManager', $entityManager); //Имя сервиса возьмите то которое у вас используется в фабрике или в конфиге доктрины
$this->serviceManager->setAllowOverride(false);
$this->entityManager = $this->serviceManager->get('entityManager');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question