diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 8c8169c90..b36ad7fb8 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2314,6 +2314,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 cd0e04b02..55e1b40b7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php @@ -152,6 +152,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();