Using the entity repositories

Entity repositories are classes responsible for accessing and managing entities. Just like entities are related to the database rows, entity repositories are related to the database tables.

We have already used default entity repositories provided by Doctrine to retrieve the entities in the previous chapters. All the DQL queries should be written in the entity repository related to the entity type they retrieve. It hides the ORM from other components of the application and makes it easier to re-use, refactor, and optimize the queries.


Doctrine entity repositories are an implementation of the Table Data Gateway design pattern. For more details, visit the following website: ...

Get Persistence in PHP with Doctrine ORM now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.