diff --git a/lib/Doctrine/ORM/Proxy/ProxyFactory.php b/lib/Doctrine/ORM/Proxy/ProxyFactory.php index c3f9b5fd42e..c095bf9c0c8 100644 --- a/lib/Doctrine/ORM/Proxy/ProxyFactory.php +++ b/lib/Doctrine/ORM/Proxy/ProxyFactory.php @@ -17,6 +17,8 @@ use Doctrine\ORM\Utility\IdentifierFlattener; use Doctrine\Persistence\Mapping\ClassMetadata; +use function in_array; + /** * This factory is used to create proxy objects for entities at runtime. * @@ -170,8 +172,10 @@ private function createCloner(ClassMetadata $classMetadata, EntityPersister $ent ); } + $identifierFields = $class->identifier; foreach ($class->getReflectionProperties() as $property) { - if (! $class->hasField($property->name) && ! $class->hasAssociation($property->name)) { + // Skip identifiers, too + if (in_array($property->name, $identifierFields) || (! $class->hasField($property->name) && ! $class->hasAssociation($property->name))) { continue; } diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index a3f1794899b..845c03c6c0d 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2747,6 +2747,15 @@ public function createEntity($className, array $data, &$hints = []) foreach ($data as $field => $value) { if (isset($class->fieldMappings[$field])) { + // Skip readonly properties that have been already set + if ( + method_exists($class->reflFields[$field], 'isReadonly') && + $class->reflFields[$field]->isReadOnly() && + isset($entity->$field) + ) { + continue; + } + $class->reflFields[$field]->setValue($entity, $value); } }