symfony - there is no active transaction in catch rollback -
i have read should use method commit before persist, didn't solved problem. try use cancel entitymanager before rollback well, didn't solved problem too...
$this->em->getconnection()->begintransaction(); // suspend auto-commit if($out = $this->em->getconnection()->istransactionactive()) { var_dump($out); } try { //... work $history = new promocodehistory(); $history->setcode($code); $history->setuser($this->getuser()); $this->em->persist($history); $this->em->getconnection()->commit(); $this->em->flush(); $user = $this->getuser(); $updatedbalance = $user->getbalance() + $code->getsum() - $sum; $user->setbalance($updatedbalance); $this->em->persist($user); $this->em->getconnection()->commit(); $this->em->flush(); $payment = new payment(); $payment->setsum($sum); $payment->setuser($this->getuser()); $payment->setpromocode($code); .... } catch (\exception $e) { if(!$out = $this->em->getconnection()->istransactionactive()) { var_dump($out); } $this->em->getconnection()->rollback(); } before try block istransactionactive() returned me true, in catch block method retrurn me false. how fix it?
i solved problem:
$this->em->getconnection()->begintransaction(); // suspend auto-commit $this->em->getconnection()->setautocommit(false);
Comments
Post a Comment