Not a valid entity or mapped super class

2019-04-04 05:27发布

问题:

I have 2 bundles, 1 CMS bundle that will be the parent bundle. I have in both bundles duplicated entitys. Like User The user in the CMS bundle i made it a abstract class. (not sure if that is the right choice. Actually, what I want is extending my user entity IF needed.).

cms user:

abstract class User implements UserInterface

bundle user:

use MV\CMSBundle\Entity\User as BaseUser;

/**
 * @ORM\Entity(repositoryClass="MV\NameBundle\Repository\UserRepository")
 * @DoctrineAssert\UniqueEntity(fields={"email"}, message="user.email.already.exist" )
 */
class User extends BaseUser
{
    ....
}

Im getting the error Class "MV\CMSBundle\Entity\User" is not a valid entity or mapped super class.

I have searched in the documentation of symfony and found this page: entities-entity-mapping but they didn't add some content xD

Oh, and no I dont want to use FOSUserBundle ;)

Symfony: 2.1

回答1:

Define the base-class as follows:

/**
 * @ORM\MappedSuperclass
 */
abstract class BaseUser
{
    // ...
}

Define the real entity:

/**
 * @ORM\Entity
 */
class User extends BaseUser
{
    // ...
}

Because you're missing the @MappedSuperclass annotation on the base-class, Doctrine throws the exception you mention.



回答2:

In my case I was missing * @ORM\Entity in my class definition.

/**
 * @ORM\Entity
 * @ORM\Table(name="listtype")
 */
class ListType
{
    ...
}


回答3:

In my case, the problem was eaccelerator because it strips out all the comments which Doctrine uses. After disabling eaccelerator it worked . You can disable your php settings or,

in the web/app_dev.php or web/app.php file.

<?php
    ini_set('eaccelerator.enable', 0);
    ini_set('eaccelerator.optimizer', 0);
    //rest of the code.

Note: Do clear the symfony2 cache after disabling this.



回答4:

I had the same problem. But to make it work but, I had to shift the lines:

* @ORM\Table
* @ORM\Entity