tirenweb
tirenweb

Reputation: 31709

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

I'm getting this error when I try to clear the cache (for example):

[Doctrine\ORM\Mapping \MappingException] Class Aib\PlatformBundle\Entity\User is not a valid entity or mapped super class.

This is User.php:

<?php
// src/Aib/PlatformBundle/Entity/User.php

namespace Aib\PlatformBundle\Entity;

use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 */
class User extends BaseUser
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    public function __construct()
    {
        parent::__construct();
        // your own logic
    }

}

And this is the place where User.php is stored:

javier@javier:~/programacion/aib/src/Aib/PlatformBundle/Entity$ ls User.php UserRepository.php

This is the AppKernel.php:

public function registerBundles()
{
    $bundles = array(
        ...
        new Aib\PlatformBundle\AibPlatformBundle(),
        ...
    );

sf 2.0.4

Upvotes: 5

Views: 13371

Answers (6)

Baptiste Donaux
Baptiste Donaux

Reputation: 1310

If you inherited from mapped class, you can add @ORM\SuperMappedClass in entity's annotation. You can read most information in this article.

Upvotes: 0

Chris
Chris

Reputation: 21

I had the same problem and it turned out to be the app/config/config.yml

It needed the defintion of the default bundle as below NameBundle, then it worked fine

orm:
    auto_generate_proxy_classes: %kernel.debug%
    default_entity_manager: default
    entity_managers:
      default:
        mappings:
          NameBundle: ~

Upvotes: 2

Reza S
Reza S

Reputation: 9748

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

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

Upvotes: 13

Christian Vermeulen
Christian Vermeulen

Reputation: 576

In my case the problem was solved by changing my servers cache from eAccelerator to APC. Apparently eAccelerator strips all the comments from files which breaks your annotations.

Upvotes: 1

mogoman
mogoman

Reputation: 2298

I had the same error, but this was because I wasn't including the Sonata Application:

try this:

add a line to your AppKernel.php

$bundles = array(
...
new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
...

Upvotes: 0

MadManMonty
MadManMonty

Reputation: 816

I had the exact same experience with my implementation of the FOS UserBundle and found I was able to resolve the issue by removing the MyBundle\Resources\config\doctrine folder.

I dont fully understand the cause (newbie) but think the issue is a result of having database content built in bother directions, ie from doctrine entities and by reverse engineering some tables.

Upvotes: 4

Related Questions