-1

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 'App\Entity\User\User'.

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 App\Entity\User;

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="App\Entity\User\User" 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)

Mouke
  • 854
  • 1
  • 7
  • 19
  • AppBundles are no longer needed for Symfony 5 and their usage is discouraged. Having said that, your dir path is wrong. Start with "%kernel.project_dir% and work from there. – Cerad Apr 26 '20 at 21:58
  • @cerad : Adding %kernel.project_dir% isn't the issue : dir is already at the root of my bundle – Mouke Apr 27 '20 at 08:11

2 Answers2

0

I fixed it in my project by adding another 'prefix' key to configuration.

Example

prefix: 'App\Account\Domain'
-1

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.

Mouke
  • 854
  • 1
  • 7
  • 19
  • I debugged a bit and it seems that if the classes are organized in folders, the XML file names must have a prefix equal to the subfolder path, replacing the folder separator with a dot. For example, if a class A is defined in a folder "Dir", the name of the XML file must be "Dir.A.orm.xml". – zeusi83 Feb 01 '23 at 15:58