Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not a valid entity or mapped super class

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

like image 944
Mitchel Verschoof Avatar asked Feb 02 '13 13:02

Mitchel Verschoof


4 Answers

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

/**
 * @ORM\Entity
 * @ORM\Table(name="listtype")
 */
class ListType
{
    ...
}
like image 143
Reza S Avatar answered Nov 20 '22 01:11

Reza S


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.

like image 28
Jasper N. Brouwer Avatar answered Nov 20 '22 00:11

Jasper N. Brouwer


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.

like image 5
ravi404 Avatar answered Nov 19 '22 23:11

ravi404


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

* @ORM\Table
* @ORM\Entity 
like image 5
apollo kalibbala Avatar answered Nov 20 '22 00:11

apollo kalibbala