DDC-601: UnitOfWork commit order problem
Author: doctrinebotCreated May 19, 2010Updated Sep 30, 2026
LabelsBugWon't FixCan't Fix
Jira issue originally created by user exxbrain:
The next critical case doesn't work, because of Duplicate entry error:
$obj = $repository->findOneByUniqueKey($key);
if ($obj != null) {
$em->remove($obj);
}
$obj = new Object();
$obj->setUniqueKey($key);
$em->persist($obj);
$em->flush();Instead of that i must use the next construction:
$obj = $repository->findOneByUniqueKey($key);
if ($obj != null) {
$em->remove($obj);
$em->flush(); // the possible data inconsistency cause
}
$obj = new Object();
$obj->setUniqueKey($key);
$em->persist($obj);
$em->flush();Source: doctrine/orm