Class is not a valid entity or mapped super class – ZF3

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 :

ORM doctrine - loading data - error

If that helps anyone, I’ll be glad so do not hesitate to drop a comment.

One response to “Class is not a valid entity or mapped super class – ZF3”

  1. Abin John says:

    Thank you. It really helps me.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Want more information?

Related links will be displayed within articles for you to pick up another good spot to get more details about software development, deployment & monitoring.

Stay tuned by following us on Youtube.

%d bloggers like this: