Screening Entry Level

What is a Doctrine entity and how do you define one in Symfony? Explain the role of attributes, the entity manager, and repositories.

Quick Tip

Show the lifecycle: "I define an entity with ORM attributes, persist it with the entity manager, and call flush to write to the database. For retrieval, I use repository methods — findOneBy for single results, custom QueryBuilder methods for complex queries."

What good answers include

Entities are plain PHP classes that Doctrine maps to database tables. Properties map to columns using ORM attributes (#[ORM\Column], #[ORM\Id], etc.). The EntityManager handles persistence: persist() marks new entities for insertion, flush() writes all pending changes to the database. Repositories provide methods for querying: findOneBy(), findBy(), and custom query methods using QueryBuilder or DQL. Symfony generates repositories automatically when you specify repositoryClass in the entity attribute. Strong candidates explain: that entities should not depend on the framework, the difference between persist and flush, that flush is a single database transaction, and the make:entity command for scaffolding.

What interviewers are looking for

Entry-level Doctrine question. Candidates who cannot explain the persist/flush distinction will misuse the entity manager. Those who understand that flush batches all changes into one transaction demonstrate basic ORM awareness.

← All Symfony questions