"Class XXX is not a valid entity or mapped superclass" after moving the class in the file system

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

I had no problems trying to create a form class through

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

Now I changed the namespace to Aib \ PlatformBundle \ Entity \ Identity \ User, but when I try to generate the form with the task that I said earlier it says:

"The class Aib \ PlatformBundle \ Entity \ User is not a valid entity or superclass mapped."

This is the contents of the file:

<?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

+77
php symfony doctrine2 doctrine-orm
Oct 19 '11 at 11:25
source share
11 answers

If this problem - do not forget the annotation * @ORM\Entity , as shown below:

 /** * Powma\ServiceBundle\Entity\User * * @ORM\Entity * @ORM\Table(name="users") */ 
+195
Mar 15 2018-12-12T00: 00Z
source share

This issue also had this topic yesterday. I created an object with a display in a new package (for example, MyFooBundle / Entity / User.php), performed the entire configuration according to the documents, but received the same error when trying to download the application.

In the end, I realized that I did not load MyFooBundle in AppKernel:

 new My\FooBundle\MyFooBundle() 

A great way to debug is to run this command:

 app/console doctrine:mapping:info 
+14
Sep 03
source share

Check the config.yml file should contain the following:

 # 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 package to the list of mappings.

+13
Jul 16 '12 at 1:16
source share

In my case, the problem was resolved by changing the server cache from eAccelerator to APC . Obviously, eAccelerator removes all comments from files that break your annotations.

+7
Jul 17 '12 at 19:29
source share

I solved this by passing false as the second parameter to Doctrine\ORM\Configuration::newDefaultAnnotationDriver .

It took me a while to dig through Google and the source code.

My case was special because I used a mapping pointing to another directory that was not related to installing Symfony, as I also had to use outdated code.

I recycled obsolete objects and they stopped working. They used to use @Annotation instead of @ORM\Annotation , so after refactoring they simply couldn’t read the metadata. Without using a simple annotation reader, everything looks fine.

+7
Oct 18 '14 at 1:49
source share

big thanks to Mark Fu and the fan

I knew that this should be somewhere in config.yml ... and be able to test it for

 app/console doctrine:mapping:info 

really helped!

In fact, this command simply stops when an error occurs ... there is no feedback, but when everything is in order, you should be able to see all the entities listed.

+6
Oct 9 '13 at
source share

I solved this problem by setting $useSimpleAnnotationReader=false when creating the MetaDataConfiguration .

+6
Jul 10 '15 at 9:03
source share

I resolved the same exception by deleting the conflicting auto-generated orm.php file in the Resources / config / doctrine folder; according to the documentation: "A package can only accept one metadata definition format. For example, it is not possible to map YAML metadata definitions to annotated PHP class entity definitions."

+3
Jun 21. '13 at 22:48
source share

You are very likely to have PHP 5.3.16 (Symfony 2.x will not work with it). In any case, you should load the verification page http://you.site.name/config.php If the project did not work on the hosting server, the following lines should be deleted in "config.php":

 if (!in_array(@$_SERVER['REMOTE_ADDR'], array( '127.0.0.1', '::1', ))) { header('HTTP/1.0 403 Forbidden'); exit('This script is only accessible from localhost.'); } 

Good luck!

+1
Jan 08 '13 at 22:24
source share

In my case, I was too jealous during refactoring and deleted the yml doctrine file!

0
Apr 17 '19 at 18:27
source share

I got rid of the same error message as in your case using app / console_dev, not just the application / console

-one
Aug 10 2018-12-12T00:
source share



All Articles