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?

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.
@ORM\Entity(repositoryClass="App\Repository\UserRepository")
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
Links
You can find more about this error here.
Leave a Reply