Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-2175

Optimistic locking version not refreshed on update for class table inheritance

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: 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

        colin Colin Campbell created issue -
        colin Colin Campbell made changes -
        Field Original Value New Value
        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.

        {code}
        --- 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(), t
        + }
                         $id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
                         $this->assignDefaultVersionValue($entity, $id);
                     }
        {code}

        The new code then looks like this:

        {code}
                    // 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);
                    }
        {code}


        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.

        {code}
        --- 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);
                     }
        {code}

        The new code then looks like this:

        {code}
                    // 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);
                    }
        {code}


        beberlei Benjamin Eberlei made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.3.2 [ 10324 ]
        Resolution Fixed [ 1 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={expand=changesets[0:20].revisions[0:29],reviews, query=DDC-2175}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

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

            Dates

            • Created:
              Updated:
              Resolved: