Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Class XXX is not a valid entity or mapped super class" after moving the class in the filesystem

I had an entity class in Aib\PlatformBundle\Entity\User.php

I had no problems trying to create its form class through

php app/ console doctrine:generate:form AibPlatformBundle:User

Now I have change the namespace to Aib\PlatformBundle\Entity\Identity\User, but when I try to generate the form with the task I said before it says:

"Class Aib\PlatformBundle\Entity\User is not a valid entity or mapped super class."

This is the file content:

<?php
namespace Aib\PlatformBundle\Entity\Identity;

use Doctrine\ORM\Mapping as ORM;

    /**
     * Aib\PlatformBundle\Entity\Identity\User
     *
     * @ORM\Table()
     * @ORM\Entity(repositoryClass="Aib\PlatformBundle\Entity\Identity
    \UserRepository")
     */
    class User
    {
    ...

Any idea?

symfony2.0.4

like image 844
ziiweb Avatar asked Oct 19 '11 11:10

ziiweb


4 Answers

Had this problem - don't forget the annotation * @ORM\Entity like below:

/**
 * Powma\ServiceBundle\Entity\User
 *
 * @ORM\Entity
 * @ORM\Table(name="users")
 */
like image 56
Mike Avatar answered Nov 11 '22 03:11

Mike


Had this problem yesterday and found this thread. I created the entity with the mapping in a new bundle (e.g. MyFooBundle/Entity/User.php), did all the configuration according to the docs but got the same error from above when trying to load the app.

In the end I realized that I wasn't loading MyFooBundle in AppKernel:

new My\FooBundle\MyFooBundle()

A great way to debug this is to run this command:

app/console doctrine:mapping:info
like image 34
mogoman Avatar answered Nov 11 '22 02:11

mogoman


Do check your config.yml file, should be containing something like this:

# Doctrine Configuration
doctrine:
    dbal:
        driver:   %database_driver%
        host:     %database_host%
        port:     %database_port%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  UTF8
        types:
            json: Sonata\Doctrine\Types\JsonType

    orm:
        auto_generate_proxy_classes: %kernel.debug%
        # auto_mapping: true
        entity_managers:
            default:
                mappings:
                    FOSUserBundle: ~
                    # ApplicationSonataUserBundle: ~
                    YourUserBundle: ~
                    SonataUserBundle: ~

Add your own bundle to the mappings list.

like image 13
Mark Fu Avatar answered Nov 11 '22 02:11

Mark Fu


I resolved this issue by setting $useSimpleAnnotationReader=false when creating the MetaDataConfiguration.

like image 11
gruentee Avatar answered Nov 11 '22 03:11

gruentee