Entities not detected with aliased namespace imports. #6693

Closed
opened 2026-01-22 15:37:08 +01:00 by admin · 1 comment
Owner

Originally created by @aik099 on GitHub (Apr 13, 2021).

The entity class (generated mostly by DQL plugin of PhpStorm):

<?php

namespace Company\Project\DoctrineEntity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="Company\Project\DoctrineRepository\ContactUsFormSubmissionRepository")
 */
class ContactUsFormSubmission
{

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue
     */
    private $id;

    /**
     * @var string
     * @ORM\Column(type="string", length=30)
     */
    private $firstName;

    /**
     * @var string
     * @ORM\Column(type="string", length=30)
     */
    private $lastName;

}

Here is how Doctrine ORM is initiated:

// Configure database.
$db_params = array(
   'driver' => 'pdo_mysql',
   'host' => $_SERVER['DB_HOST'],
   'dbname' => $_SERVER['DB_NAME'],
   'user' => $_SERVER['DB_USER'],
   'password' => $_SERVER['DB_PASSWORD'],
);

$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . '/src/DoctrineEntity'), false);
$config->addEntityNamespace('App', 'Company\Project\DoctrineEntity');
$entity_manager = EntityManager::create($db_params, $config);
$helper_set = ConsoleRunner::createHelperSet($entity_manager);

Attempt to use orm:schema-tool:create command doesn't create any entities, because instead of resolving @ORM\Entity with the above present use Doctrine\ORM\Mapping as ORM; line to Doctrine\ORM\Mapping\Entity class it resolves it to Doctrine\ORM\Mapping\ORM\Entity class. Since it doesn't exist it's being ignored.

This happens likely due fact, that the simple annotation manager has initialized with a hardcoded Doctrine\ORM\Mapping namespace and isn't aware of the ORM alias under which it's imported.

P.S.
I'm just starting to work with Doctrine ORM, so please excuse my stupid question.

Originally created by @aik099 on GitHub (Apr 13, 2021). The entity class (generated mostly by DQL plugin of PhpStorm): ```php <?php namespace Company\Project\DoctrineEntity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity(repositoryClass="Company\Project\DoctrineRepository\ContactUsFormSubmissionRepository") */ class ContactUsFormSubmission { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue */ private $id; /** * @var string * @ORM\Column(type="string", length=30) */ private $firstName; /** * @var string * @ORM\Column(type="string", length=30) */ private $lastName; } ``` Here is how Doctrine ORM is initiated: ```php // Configure database. $db_params = array( 'driver' => 'pdo_mysql', 'host' => $_SERVER['DB_HOST'], 'dbname' => $_SERVER['DB_NAME'], 'user' => $_SERVER['DB_USER'], 'password' => $_SERVER['DB_PASSWORD'], ); $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . '/src/DoctrineEntity'), false); $config->addEntityNamespace('App', 'Company\Project\DoctrineEntity'); $entity_manager = EntityManager::create($db_params, $config); $helper_set = ConsoleRunner::createHelperSet($entity_manager); ``` Attempt to use `orm:schema-tool:create` command doesn't create any entities, because instead of resolving `@ORM\Entity` with the above present `use Doctrine\ORM\Mapping as ORM;` line to `Doctrine\ORM\Mapping\Entity` class it resolves it to `Doctrine\ORM\Mapping\ORM\Entity` class. Since it doesn't exist it's being ignored. This happens likely due fact, that the simple annotation manager has initialized with a hardcoded `Doctrine\ORM\Mapping` namespace and isn't aware of the `ORM` alias under which it's imported. P.S. I'm just starting to work with Doctrine ORM, so please excuse my stupid question.
admin closed this issue 2026-01-22 15:37:08 +01:00
Author
Owner

@beberlei commented on GitHub (Apr 13, 2021):

Yes this is how the simple annotation reader works. I believe this is documented, but don't expect any large changes in this, since with PHP 8 attributes, annotations are sort of reaching their end of life

@beberlei commented on GitHub (Apr 13, 2021): Yes this is how the simple annotation reader works. I believe this is documented, but don't expect any large changes in this, since with PHP 8 attributes, annotations are sort of reaching their end of life
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6693