9

I am using Symfony2 and when i try to generate the schema ($ php app/console doctrine:generate:schema) i got an error..

    [Doctrine\ORM\Mapping\MappingException]                                                                             
      No mapping file found named 'xxx.UserBundle.Entity.User.php' for class 'xxx\UserBundle\Entity\User'.

I only have 2 Bundles in the proyect:

  • UserBundle
  • FileBundle

I connect the FileBundle with the UserBundle with this code:

     
    /** 
    * @ORM\ManyToOne(targetEntity="xxx\UserBundle\Entity\User") 
    **/
    protected $user;      
    

The headers of the files are something like this:

    
    namespace xx\UserBundle\Entity;

    use Doctrine\ORM\Mapping as ORM;

    /** 
     * @ORM\Entity
     **/
    class User
    { ###...###}
    

FileBundle is very similar.. Thanks!

2
  • I assume xxx and xx are just substitutions, are they? Commented Mar 1, 2012 at 23:35
  • I added the answer... but it's a long shot :) Commented Mar 2, 2012 at 0:04

5 Answers 5

27

You are mixing Doctrine mapping formats, you have annotations and at least one XML file in Resources/config/doctrine

From the symfony docs:

"A bundle can accept only one metadata definition format. For example,
it's not possible to mix YAML metadata definitions with annotated PHP
entity class definitions."

So the solution is:

You cannot mix different Doctrine mapping formats in a given bundle. So either use annotations for all entities or use XML for all.

Sign up to request clarification or add additional context in comments.

2 Comments

This solved my issue and it's still a valid restriction in Symfony 2.1, see symfony.com/doc/2.1/book/doctrine.html#add-mapping-information. Thanks
thank you, honestly. this saved me tons of debugging hours. I will never use auto generation of objects again
5

It is somehow strange to me that you're using PHPDriver for ORM and not AnnotationDriver, since your database info in classes is in annotations.

Anyhow, if php app/console doctrine:mapping:info command gives you only 1 entity that means that your other bundle containing User class is not loaded in app/AppKernel.php file. Load your UserBundle by adding line

new xxx\UserBundle\xxxUserBundle(),

to the $bundles array in registerBundles() function. After that, this function should look something like this:

public function registerBundles()
{
    $bundles = array(
        new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
        new Symfony\Bundle\SecurityBundle\SecurityBundle(),
        new Symfony\Bundle\TwigBundle\TwigBundle(),
        new Symfony\Bundle\MonologBundle\MonologBundle(),
        new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
        new Symfony\Bundle\DoctrineBundle\DoctrineBundle(),
        new Symfony\Bundle\AsseticBundle\AsseticBundle(),
        new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
        new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
        new xx\FileBundle\xxFileBundle(),
        new xxx\UserBundle\xxxUserBundle(),
    );

    if (in_array($this->getEnvironment(), array('dev', 'test'))) {
        $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
        $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
        $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
    }

    return $bundles;
}

Of course, change 'xx' and 'xxx' with your real names.

Hope this helps.

Comments

4

I agree with @ilanco 100%. In addition, the solution is to REMOVE any .xml file in folder, for example:

C:\xampp\htdocs\localxyz\src\AppBundle/Resources/config/doctrine/Comment.orm.xml

these xml files created when you run such command:

C:\xampp\htdocs\localxyz>php app/console doctrine:mapping:import --force AppBundle xml

Dung.

Comments

1

Good day,

Although I know that this has been posted years ago, but will just like to post my answer here, perhaps it could help someone :)

just simply clear the cache, it works for me though

php bin/console cache:clear

Thanks

Comments

0

I can't think of a reason why this is happening but I will take a leap here.

Try editing your config.yml. doctrine section should look like this:

doctrine:
    dbal:
        default_connection: my_connection_name
        connections:
            fmefb:
                host:     %database_host%
                dbname:   %database_name%
                user:     %database_user%
                password: %database_password%
                driver:   %database_driver%
                port:     %database_port%
                charset:  UTF8

    orm:
        default_entity_manager: my_entity_manager
        entity_managers:
            my_entity_manager:
                connection: my_connection_name
                mappings:
                    CompanyNameSiteBundle: ~
                    CompanyNameAdminBundle: ~
                    CompanyNameSomethingElse: ~

Notice the mappings list on the bottom. All bundles which are "linked" are included here.

Hope this helps....

1 Comment

i use $php app/console doctrine:mapping:info Found 1 entities mapped in entity manager default: [OK] xx\FileBundle\Entity\File, any idea?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.