DDC-2175: Optimistic locking version not refreshed on update for class table inheritance #2867

Closed
doctrinebot opened this Issue Nov 28, 2012 · 1 comment

2 participants

@doctrinebot

Jira issue originally created by user colin:

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
<ins></ins><ins> b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php
@@ -227,9 </ins>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);
-
<ins>            if ($isVersioned) {
</ins>                if (! isset($updateData[$versionedTable])) {
<ins>                    $this->*updateTable($entity, $this->quoteStrategy->getTableName($versionedClass, $this->*platform), array(), true);
</ins>                }
                 $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);
            }   
@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.3.2 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment