diff --git a/src/UnitOfWork.php b/src/UnitOfWork.php index 73aae2f362..ff30f14f6d 100644 --- a/src/UnitOfWork.php +++ b/src/UnitOfWork.php @@ -2968,7 +2968,7 @@ public function createEntity($className, array $data, &$hints = []) $oid = spl_object_id($entity); $this->registerManaged($entity, $id, $data); - if (isset($hints[Query::HINT_READ_ONLY])) { + if (isset($hints[Query::HINT_READ_ONLY]) && $hints[Query::HINT_READ_ONLY] === true) { $this->readOnlyObjects[$oid] = true; } } diff --git a/tests/Tests/ORM/Functional/ReadOnlyTest.php b/tests/Tests/ORM/Functional/ReadOnlyTest.php index 4d06e107d0..297c2d5a3e 100644 --- a/tests/Tests/ORM/Functional/ReadOnlyTest.php +++ b/tests/Tests/ORM/Functional/ReadOnlyTest.php @@ -90,6 +90,24 @@ public function testReadOnlyQueryHint(): void self::assertTrue($this->_em->getUnitOfWork()->isReadOnly($user)); } + public function testNotReadOnlyQueryHint(): void + { + $user = new ReadOnlyEntity('beberlei', 1234); + + $this->_em->persist($user); + + $this->_em->flush(); + $this->_em->clear(); + + $query = $this->_em->createQuery('SELECT u FROM ' . ReadOnlyEntity::class . ' u WHERE u.id = ?1'); + $query->setParameter(1, $user->id); + $query->setHint(Query::HINT_READ_ONLY, false); + + $user = $query->getSingleResult(); + + self::assertFalse($this->_em->getUnitOfWork()->isReadOnly($user)); + } + public function testNotReadOnlyIfObjectWasProxyBefore(): void { $user = new ReadOnlyEntity('beberlei', 1234);