Skip to content

Commit

Permalink
DDC-1340 - Fix bug with merge() and optimistic lock exception
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Aug 21, 2011
1 parent 736443f commit 8c2db89
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@ private function doMerge($entity, array &$visited, $prevManagedCopy = null, $ass
$entityVersion = $class->reflFields[$class->versionField]->getValue($entity);
// Throw exception if versions dont match.
if ($managedCopyVersion != $entityVersion) {
throw OptimisticLockException::lockFailedVersionMissmatch($entityVersion, $managedCopyVersion);
throw OptimisticLockException::lockFailedVersionMissmatch($entity, $entityVersion, $managedCopyVersion);
}
}

Expand Down
22 changes: 22 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\Models\CMS\CmsPhonenumber;
use Doctrine\Tests\Models\CMS\CmsAddress;
use Doctrine\Tests\Models\CMS\CmsArticle;
use Doctrine\ORM\UnitOfWork;

require_once __DIR__ . '/../../TestInit.php';
Expand Down Expand Up @@ -192,5 +193,26 @@ public function testDetachManagedUnpersistedEntity()
$this->assertFalse($this->_em->contains($user));
$this->assertFalse($this->_em->getUnitOfWork()->isInIdentityMap($user));
}

/**
* @group DDC-1340
*/
public function testMergeArticleWrongVersion()
{
$article = new CmsArticle();
$article->topic = "test";
$article->text = "test";

$this->_em->persist($article);
$this->_em->flush();

$this->_em->detach($article);

$sql = "UPDATE cms_articles SET version = version+1 WHERE id = " . $article->id;
$this->_em->getConnection()->executeUpdate($sql);

$this->setExpectedException('Doctrine\ORM\OptimisticLockException', 'The optimistic lock failed, version 1 was expected, but is actually 2');
$this->_em->merge($article);
}
}

0 comments on commit 8c2db89

Please sign in to comment.