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
How to Create a New Joomla User Account from Within a Script
Fetching Mail from a Pop3 Server Using PHP
Add Class="Active" to Active Page Using PHP
Running Imagemagick on Xampp 1.8.3 with Windows 7
Require_Once :Failed to Open Stream: No Such File or Directory
Object of Class Stdclass Could Not Be Converted to String
PHP Date Format Yyyy-Mm-Dd Minus or Add One Week from Now
Rsa Encryption/Decryption Compatible with JavaScript and PHP
Secure User Image Upload Capabilities in PHP
Paypal Sandbox Ipn Always Returns Invalid
Convert Array of Paths into Ul List
MySQL or PHP Is Appending a  Whenever the £ Is Used
Upload Multiple Image File Using Httpurlconnection
MySQL PHP - Select Where Id = Array()
I Have a Base64 Encoded Png, How to Write the Image to a File in PHP