"Class Xxx Is Not a Valid Entity or Mapped Super Class" After Moving the Class in the Filesystem

How to fix class is not a valid entity or mapped super class?

Ok, I figured it out myself. My problem is that my config.yml was wrong. I was missing the auto_mapping: true line in my config.yml.

doctrine:
# (dbal stuff here)

orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true

After adding that, everything auto-generates fine with the php app/console doctrine:generate:entities MySite/MyBundle/Entity/User line

Class XXX is not a valid entity or a mapped super class error when using php app/console

did you create your entity using doctrine? I saw on your Job.php entity you are using annotation as mapping format.

In error output it said doctrine can't find any mapped entities. I've been there and it solved with specific configuration of your config.yml.

Try to change this on your config.yml

doctrine:
dbal:
driver: "%database_driver%"
#etc

orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: false
mappings:
MyAppMyBundle:
type: annotation #On your case it should be annotation
dir: Resources/Model/

Read this maybe it can help:

Doctrine Mapping in Symfony2 using YAML

XXX is not a valid entity or mapped super class // and config options

Ok, so my entity was correct and I don't need to call classLoader.

below is the correct initialization:

    $classLoader = new ClassLoader('Doctrine', CORE_PATH . 'external/');
$classLoader->register();

AnnotationRegistry::registerFile(CORE_PATH.'external/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');

$cache = new ArrayCache();

$annotationReader = new AnnotationReader();

$cacheReader = new CachedReader(
$annotationReader,
$cache
);

$driverChain = new DriverChain();

$annotationDriver = new AnnotationDriver(
$annotationReader,
array(CORE_PATH . 'model/')
);

$driverChain->addDriver($annotationDriver, 'gallib\core\model');

$doctrineConfig = new Configuration();

$doctrineConfig->setProxyDir(CORE_PATH . 'model/proxy');
$doctrineConfig->setProxyNamespace('gallib\core\model\proxy');
$doctrineConfig->setAutoGenerateProxyClasses(true);
$doctrineConfig->setMetadataDriverImpl($driverChain);
$doctrineConfig->setMetadataCacheImpl($cache);
$doctrineConfig->setQueryCacheImpl($cache);

$database = $this->config->database;

$connectionOptions = array(
'driver' => $database['driver'],
'dbname' => $database['dbname'],
'user' => $database['username'],
'password' => $database['password']
);

$this->em = EntityManager::create($connectionOptions, $doctrineConfig);

symfony2 is not a valid entity or mapped super class

Finally, it may be a cache optimizer issue. If you are using eAccelerator, then you will have problems, probably with Doctrine. The reason is eAccelerator removes annotations from the code! You can try APC which performs well with doctrine.

Read apc vs eaccelerator vs xcache


Have a look at

http://you.site.name/config.php

It shows you the requirements that should be present to make your application work.

AND

please expose your page entity class.


There may be many reasons for this error and your question was already asked here on SO "Class XXX is not a valid entity or mapped super class" after moving the class in the filesystem

https://github.com/symfony/symfony/issues/4554


$page=$em->getRepository('PageBundle:Page')->findOneBy(array('codi'=>'0001'));

change it to

 $page=$em->getRepository('PropaPageBundle:Page')->findOneBy(array('codi'=>'0001'));

or

 $page=$em->getRepository('Propa\PageBundle\Entity\Page')->findOneBy(array('codi'=>'0001'));

and see if it works.

symfony2 is not a valid entity or mapped super class (used super class)

Changing the line

 * @ORM\Entity(repositoryClass="UserRepository")

to

 * @ORM\Entity(repositoryClass="SilexStarter\Repository\UserRepository")

resolve the problem?



Related Topics



Leave a reply



Submit