Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2175

Optimistic locking version not refreshed on update for class table inheritance

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.3
    • Fix Version/s: 2.3.2
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      I am trying to use optimistic locking with class table inheritance. I put the version column in the base table. When I perform change a base entity value, persist, and flush, the version in memory does not update to match the new version in the base table. Consequently, subsequent updates fail with "The optimistic lock on an entity failed."

      As far as I can tell, the reason is that the update method in Doctrine/ORM/Persisters/JoinedSubclassPersister.php does not call assignDefaultVersionValue in this case.

      This change appears to fix the problem.

      --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php
      +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php
      @@ -227,9 +227,10 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
       
                   // Make sure the table with the version column is updated even if no columns on that
                   // table were affected.
      -            if ($isVersioned && ! isset($updateData[$versionedTable])) {
      -                $this->_updateTable($entity, $this->quoteStrategy->getTableName($versionedClass, $this->_platform), array(), true);
      -
      +            if ($isVersioned) {
      +                if (! isset($updateData[$versionedTable])) {
      +                    $this->_updateTable($entity, $this->quoteStrategy->getTableName($versionedClass, $this->_platform), array(), true);
      +                }
                       $id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
                       $this->assignDefaultVersionValue($entity, $id);
                   }
      

      The new code then looks like this:

                  // Make sure the table with the version column is updated even if no columns on that
                  // table were affected.
                  if ($isVersioned) {
                      if (! isset($updateData[$versionedTable])) {
                          $this->_updateTable($entity, $this->quoteStrategy->getTableName($versionedClass, $this->_platform), array(), true);
                      }   
                      $id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
                      $this->assignDefaultVersionValue($entity, $id);
                  }   
      

        Activity

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Colin Campbell
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: