Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2929

Pessimistic lock on Query does not update the entity with the DB values if it's already cached

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: Git Master
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      PHP 5.4.13-1~dotdeb.1

      Description

      When asking for a pessimistic lock through a Query object, the entities already in the cache are not refreshed with the latest values from the database (unless you set the Query::HINT_REFRESH hint)

      Example:

              $em->beginTransaction();
              try {
                  $bar = $em->createQuery('SELECT b FROM Foo:Bar b WHERE b.id = :id')
                              ->setParameter('id', 150)
                              ->getSingleResult();
                  var_dump($bar->getAmount()); // Yields some positive value
                  $bar->setAmount(0);
                  $bar = $em->createQuery('SELECT b FROM Foo:Bar b WHERE b.id = :id')
                              ->setParameter('id', 150)
                              ->setLockMode(\Doctrine\DBAL\LockMode::PESSIMISTIC_WRITE)
                              // ->setHint(\Doctrine\ORM\Query::HINT_REFRESH, true)
                              ->getSingleResult();
                  var_dump($bar->getAmount()); // Yields 0
      
                  $em->flush();
                  $em->commit();
              } catch (\Exception $e) {
                  $em->rollback();
              }
      

      This is similar to DDC-1846

      (Tested on 2.4.0 and 2.4.1)

        Issue Links

          Activity

          There are no comments yet on this issue.

            People

            • Assignee:
              Benjamin Eberlei
              Reporter:
              Renaud Drousies
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: