From 4a71f2ac409eb4fc39f6b6dd2f6573b8c166bc66 Mon Sep 17 00:00:00 2001 From: Carnage Date: Sat, 10 Jan 2015 13:59:29 +0000 Subject: [PATCH 1/2] Added test to demonstrate issue --- .../Tests/ORM/Functional/Locking/OptimisticTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php index e6773dd6b87..3ce6437f399 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php @@ -150,6 +150,19 @@ public function testStandardFailureThrowsException(OptimisticStandard $entity) } } + 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(); From 9f1a73d4cc4f22c994e5565b856fc8f43a7077f4 Mon Sep 17 00:00:00 2001 From: Carnage Date: Sat, 10 Jan 2015 13:59:42 +0000 Subject: [PATCH 2/2] Fixed issue --- lib/Doctrine/ORM/UnitOfWork.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index c0e681bcea8..577e7953597 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2344,6 +2344,10 @@ public function lock($entity, $lockMode, $lockVersion = null) return; } + if ($entity instanceof Proxy && !$entity->__isInitialized__) { + $entity->__load(); + } + $entityVersion = $class->reflFields[$class->versionField]->getValue($entity); if ($entityVersion != $lockVersion) {