As a way to help others and myself, I will continue to post Zend3 typical errors and their fix regularly.
To reproduce the following error :
“Class is not a valid entity or mapped super class” using ZF3 and Doctrine 2″
I’ve used the Yaml driver as described in this page, then switched back to the default Doctrine driver in my module.config.php file.
And now when I need to append new data inside my table using data-fixtures, I’m having the above issue.
Fix the Class is not a valid entity or mapped super class error
The reason is actually obvious as when you are using the Yaml driver, once you load the data in the database from the command line and the entities are auto generated, annotations are filled but they are different from the default Doctrine 2 ORM annotations.
In order to fix the error, you should replace annotations to match these ones :
use Doctrine\ORM\Mapping as ORM; /** * This class represents a country. * @ORM\Entity * @ORM\Table(name="country") */
Replace the country class by whatever needed class and add the following annotations on top of your variable :
/** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(name="id") */ protected $id;
Now load your data and everything should go fine :
If that helps anyone, I’ll be glad so do not hesitate to drop a comment.