diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 758754202..8789b5f81 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2353,6 +2353,10 @@ class UnitOfWork implements PropertyChangedListener return; } + if ($entity instanceof Proxy && !$entity->__isInitialized__) { + $entity->__load(); + } + $entityVersion = $class->reflFields[$class->versionField]->getValue($entity); if ($entityVersion != $lockVersion) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php index e6773dd6b..3ce6437f3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php @@ -150,6 +150,19 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase } } + public function testLockWorksWithProxy() + { + $test = new OptimisticStandard(); + $test->name = 'test'; + $this->_em->persist($test); + $this->_em->flush(); + $this->_em->clear(); + + $proxy = $this->_em->getReference('Doctrine\Tests\ORM\Functional\Locking\OptimisticStandard', $test->id); + + $this->_em->lock($proxy, LockMode::OPTIMISTIC, 1); + } + public function testOptimisticTimestampSetsDefaultValue() { $test = new OptimisticTimestamp();