Previous Blogs

Tags

 

Fatal Error: 'Class is not a valid entity or mapped super class.' in Doctrine 2

Posted by Elsabe on October 17, 2011

Wanted to quickly push some code onto a remote server for a client to test / review some functionality  and I got a real nasty looking exception on the front page, from the Doctrine 2 Mapper.

 
Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 
'Class models\LoginAttempts is not a valid entity or mapped super class.' in 
/application/libraries/Doctrine/ORM/Mapping/MappingException.php:137 
Stack trace: #0
/application/libraries/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php(138): 
Doctrine\ORM\Mapping\MappingException::classIsNotAValidEntityOrMappedSuperClass(
'models\LoginAtt...') #1
/application/libraries/Doctrine/ORM/Mapping/ClassMetadataFactory.php(282): 
Doctrine\ORM\Mapping\Driver\AnnotationDriver->loadMetadataForClass('
models\LoginAtt...', Object(Doctrine\ORM\Mapping\ClassMetadata)) #2 
/application/libraries/Doctrine/ORM/Mapping/ClassMetadataFactory.php(169): 
Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata('models\LoginAtt...') #3 
/application/libraries/Doctrine/ORM/EntityManager.php(247): 
Doctrine\ORM\Mapping\ClassMetadataFactory->getMeta in 
/application/libraries/Doctrine/ORM/Mapping/MappingException.php 
on line 137
 

The code base worked perfectly on localhost, but broke on remote. Joy in a jam jar!

Couldn't find a conclusive answer on the interwebs, and was about to give up when I noticed eAccelerator was installed on the server. Disabling eAccelerator did the trick! Turns out that eAccelerator strips away PHP doc blocks, which makes Doctrine 2's annotation mapping freak out completely.

Disable eAccelerator:

Add the following two lines in your htaccess file in the root of the web dir.

php_flag eaccelerator.enable 0
php_flag eaccelerator.optimizer 0
 

So now that I know what's wrong I've found a bunch of forum posts that would've helped. Nice post explaining eAccelerator and Doctrine 2 not playing well together at wildlyinaccurate.com.

Tags

  • CodeIgniter
  • Doctrine
  • PHP

Comments:

Leave a Reply



(Your email will not be publicly displayed.)

Please type the letters and numbers shown in the image.Captcha CodeClick the image to see another captcha.