The problem was that ServiceEntityRepository should be extended in a repository class, not an entity class.
as it is mentioned here, there is no good description for auto-generating repositories from an existing database.
This is my entity class with its annotations:
/**
* Sms
*
* @ORM\Table(name="sms")
* @ORM\Entity(repositoryClass="App\Repository\SMSRepository")
*/
class Sms
{ ... }
this line is very important:
@ORM\Entity(repositoryClass="App\Repository\SMSRepository")
another important thing is to removing Entity from excluding in the services.YAML file.
if you set a name for the repository of your entity class by annotation, by running this command you will have your repository generated:
php bin\console make:entity --regenerate
and you can simply write you complex queries in the repository file which is generated by the aforementioned command.
for calling methods of your repository class you can use this in your controller files:
$this->getDoctrine()->getRepository(EntityFile::class)->youFunctionNameInRepositoryFile()
be careful about the argument of the getRepository which is the Entity file, not the repository file.
$this->container->get(ManagerRegistry::class). Just inject theManagerRegistryinto your controller or override the service definition and make it public.ServiceEntityRepositoryis just anoptional EntityRepository base class with a simplified constructor (for autowiring).. I don't see any bad practice extending it - as it's meant to be. The class-nameSmsmight indicate a "bad" approach but it doesn't necessarily from the code in the question. Changing the class-name toSmsRepositorymight be more obvious, agreed :)