Namespace doesn't contain mapped entities in S

2019-08-14 22:43发布

问题:

I've created a new entity in src/Andrei/StatisticsBundle/Entity/Attribute/Value/ButtonVarchar.php. Here is the code for this class:

<?php

namespace Andrei\StatisticsBundle\Entity\Attribute\Value;

class ButtonVarchar
{
    protected $value;
}

and in src/Andrei/StatisticsBundle/Resources/config/doctrine/ButtonVarchar.yml I defined the following mapping information:

Andrei\StatisticsBundle\Entity\Attribute\Value\ButtonVarchar:
    type: entity
    table: button_attribute_value_varchar
    id:
        id:
            type: integer
            generator: { strategy: AUTO }
    fields:
        value: 
            type: string
            length: 255
    manyToOne:
        button:
            targetEntity: Button
            inversedBy: attributeValues
            joinColumn:
                name: button_id
                referencedColumnName: id

For some reason when I run php app/console doctrine:generate:entities I get the following error:

[RuntimeException] Namespace "Andrei\StatisticsBundle\Entity\Attribute\Value" does not contain any mapped entities. 

I can't understand why is this happening. Can someone point me to the right direction? Thank you.

回答1:

Did you add your StatisticsBundle to Doctrine config?

eg:

doctrine:
  orm:
    auto_mapping: true
    mappings:
         AndreiStatisticsBundle: ~

You can see mapping problem in the following link:

https://github.com/symfony/symfony/pull/675



回答2:

It seems that your entities are separated into fine grained packages. In that case you need to specify fully qualified namespace in order for it to work.

 targetEntity: Fully\Qualified\Namespace\To\Button


回答3:

It may also help.

This works:

MyUniqBundle:Entity

This doesn't work:

MyUniqBundle/Entity