Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2930

Pessimistic locking using $em->find('Entity', $id, LockMode::PESSIMISTIC_WRITE) and $em->lock($entiy, LockMode::PESSIMISTIC_WRITE) differs in (not)refreshing entity state from DB

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.4.1
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      ubuntu 12.04, mysql, zf2

      Description

      When using pessimistic locking on MySQL(InnoDB tables) there is difference which surprised me:

      $em->find('Entity', $id, LockMode::PESSIMISTIC_WRITE);
      

      will reload entity state from DB even when entity was already managed in cache (implemented in DDC-2929)
      So I supposed that

      $em->lock($entiy, LockMode::PESSIMISTIC_WRITE);
      

      will work alike even when in this case entity is sure already loaded and managed
      But it is not the case, actual query log showed only

      SELECT 1 FROM table WHERE id FOR UPDATE
      

      If this difference is intended it would be nice to mention it in http://docs.doctrine-project.org/en/latest/reference/transactions-and-concurrency.html

      As a workaround I use

      $em->refresh($entiy);
      

        Activity

        There are no comments yet on this issue.

          People

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

            Dates

            • Created:
              Updated: