Introduction

I was recently working on a console application in Symfony and I had an Entity file called “Record.php”. Whenever I tried to run:

php bin/console doctrine:generate:entities AppBundle/Entity/Record

I would always get a Doctrine\ORM\MappingException Class “AppBundle\Entity\Record” is not a valid entity or mapped super class. error as shown in the following screenshot:

Doctrine_MappingException

Annotation Spacing Problem

I know I had the correct Doctrine annotations specified, since I referred to working Entities in other projects, so I was baffled as to what could be the problem. I decided to change the indentation of the @ORM\Entity annotation. This fixed the problem.

Apparently, if you have a tab instead of a single space, the annotation does not get recognized. I had a similar problem that I noticed with the Symfony Route annotation.

The way to see the problem is to turn on whitespace visibility in the IDE you use. In Eclipse, you would go to “Window > Preferences” and then view under “General > Editors > Text Editors” and select the checkbox “Show whitespace characters”. The tab will look like this:

Eclipse_whitespace

Change the tab to space and then rerun the “doctrine:generate:entities” and it should work for you.

Hopefully this will help someone out! I struggled for a while on this.

Advertisement