Skip to content
Advertisement

Symfony5/Doctrine can’t find my XML mapping file for my entity

I am currently trying to set up from scratch a Symfony 5 project using Doctrine with XML mapping.

I created a simple AppBundle with some entities. After trying to generate my migration, I have this error :

No mapping file found named ‘User.orm.xml’ for class ‘AppEntityUserUser’.

A quick google search tells me it might be a conflict with annotations (which I don’t use and can’t find any occurence).

I feel like i’m missing something stupidly simple and I need help.

My entity :

<?php
namespace AppEntityUser;

final class User implements UserInterface
{
use IdentifiableTrait;

private string $name;

private Collection $tasks;

public function __construct()
{
    $this->tasks = new ArrayCollection();
}

public function getName(): string
{
    return $this->name;
}

public function setName(string $name): UserInterface
{
    $this->name = $name;

    return $this;
}

public function getTasks(): Collection
{
    return $this->tasks;
}

public function addTask(TaskInterface $task): UserInterface
{
    if (!$this->tasks->contains($task)) {
        $this->tasks->add($task);
        $task->setUser($this);
    }

    return $this;
}

public function removeTask(TaskInterface $task): UserInterface
{
    if ($this->tasks->contains($task)) {
        $this->tasks->removeElement($task);
    }

    return $this;
}
}

My User.orm.xml file (location : config/doctrine/User/):

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                          https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

   <entity name="AppEntityUserUser" table="users">
       <id name="id" type="integer" column="id"/>
       <field name="name" column="name"/>
   </entity>

</doctrine-mapping>

My config/packages/doctrine.yaml file :

doctrine:
dbal:
    url: '%env(resolve:DATABASE_URL)%'

orm:
    mappings:
        App:
            is_bundle: false
            type: xml
            dir: '%kernel.project_dir%/config/doctrine'

I really don’t see what i’m missing.

Regards, Mouke

EDIT : After reading @cerad comment, I decided to remove the bundle part and just use SF5 new file architecture. The issue is still there tho. Note that if I change the name of User.orm.xml (for instance, user.orm.xml), it detects it and change the error according to the name (case mismatch for user.orm.xml)

Advertisement

Answer

Found the issue.

First of all, thanks @cerad for the advice regarding bundles.

Concerning my issue, I wanted to sort my entities into subfolders : Entity/User/User.php. That subfolder was the issue. As soon as I removed it (both for the class and the orm.xml file), it worked.

Thanks all.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement