Web Development

how to fix doctrine symfony entity has a repositoryClass set to “entity name”, but this is not a valid class. Check your class naming

So you got this error while trying to access a repository from a Service or somewhere else. So what went wrong and what does this mean?

baby what does that even mean meme
What does this even mean?

Well it probably means that you did not use a fully qualified name for the repositoryClass statement or you do not have one at all.

Basically Doctrine needs to know where the repository for an Entity is located. It can be anywhere. If you define the repository like this

 * User
 * @ORM\Table(name="user", uniqueConstraints={@ORM\UniqueConstraint(name="email_UNIQUE", columns={"email"})}, indexes={@ORM\Index(name="email", columns={"email"})})
 * @ORM\Entity(repositoryClass=UserRepository::class)

Then Doctrine looks in the same directory as your Entity aka the entity folder and since it can’t find it you get this error. I found that adding a simple use statement to the top of the Entity file like so works well.

use App\Repository\UserRepository;

You can also just add the fully qualified Repository name like this.


It is a personal choice thing. I like the use statements because I am using PHP storm and it does use statements better than it does suggesting Repository names in the Entity annotations. Actually it doesn’t suggest the fully qualified path name so that is why I personally use “use” LOL


You can find more about this error here.

Resources Web Development

Symfony errors and exception handling resources

How to customize error pages – Documentation page about how to create custom error pages.
How to Customize Access Denied Responses – specifically about how to customize access denied responses. This is useful for when you use voters to authorize a users access to content.