DDC-1220: UnitOfWork commit order problem #1535

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

Originally created by @doctrinebot on GitHub (Jun 21, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user citronbleu-v:

DDC-601 is not resolved for me because if I would validate my entity before to persist. How do ? If there are an error I would to keep the old entity.

$em->getConnection()->beginTransaction();
try {
    if ($obj != null) {
        $em->remove($obj);
       //  $em->flush(); <=== Not possible ! for my case.
    } 
    $obj = new Object();
    $obj->setUniqueKey($key);

    if ($this->service('Ogj')->isValid($obj))
    {
        $em->persist($obj);
        $em->flush(); // <=== ERROR : SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
    }
    else
        throw new Exception('Entity is not valid');

    $em->getConnection()->commit();
} catch (Exception $e) {
   $em->getConnection()->rollback();
   $em->close();
   throw $e;
}
Originally created by @doctrinebot on GitHub (Jun 21, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user citronbleu-v: [DDC-601](http://www.doctrine-project.org/jira/browse/DDC-601) is not resolved for me because if I would validate my entity before to persist. How do ? If there are an error I would to keep the old entity. ``` $em->getConnection()->beginTransaction(); try { if ($obj != null) { $em->remove($obj); // $em->flush(); <=== Not possible ! for my case. } $obj = new Object(); $obj->setUniqueKey($key); if ($this->service('Ogj')->isValid($obj)) { $em->persist($obj); $em->flush(); // <=== ERROR : SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry } else throw new Exception('Entity is not valid'); $em->getConnection()->commit(); } catch (Exception $e) { $em->getConnection()->rollback(); $em->close(); throw $e; } ```
admin closed this issue 2026-01-22 13:17:15 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jul 8, 2012):

Comment created by @beberlei:

You should use EntityManager#merge() instead of #persist()

@doctrinebot commented on GitHub (Jul 8, 2012): Comment created by @beberlei: You should use EntityManager#merge() instead of #persist()
Author
Owner

@doctrinebot commented on GitHub (Jul 8, 2012):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Jul 8, 2012): 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#1535