#12172·orm

initializeObject() throws exception for non-managed objects with native lazy objects

Author: SherinBloemendaalCreated Sep 19, 2025Updated Sep 19, 2026

Bug Report

Q A
Version 3.5.x
Previous Version if the bug is a regression N/A (new feature bug)

Summary

When isNativeLazyObjectsEnabled() is true, calling EntityManager::initializeObject() or UnitOfWork::initializeObject() with a non-managed object throws an exception instead of performing a no-op as specified by the ObjectManager interface contract.

Current behavior

Calling initializeObject() on objects that are not Doctrine entities results in an exception:

The class 'App\Dto\TestDto' was not found in the chain configured namespaces App\Entity

This breaks the documented interface contract which states the method should be "a no-op for other objects."

Expected behavior

According to the ObjectManager interface documentation:

https://github.com/doctrine/persistence/blob/b0bb31ae055a8dd23b6aaf57bc5b26aa8d94d111/src/Persistence/ObjectManager.php#L114-L119

The method should silently do nothing when called with non-Doctrine entities, not throw an exception.

How to reproduce

php
<?php
use Doctrine\ORM\ORMSetup;
use Doctrine\ORM\EntityManager;

$config = ORMSetup::createAttributeMetadataConfiguration([__DIR__ . '/src'], true);
$config->enableNativeLazyObjects(true);
$entityManager = EntityManager::create($connectionParams, $config);

$nonEntity = new stdClass();
$nonEntity->someProperty = 'test';

$entityManager->initializeObject($nonEntity);
// Exception: The class 'stdClass' was not found in the chain configured namespaces