The Implications of Using Doctrine's EntityRepository vs. ServiceEntityRepository
The article discusses the implications of using Doctrine's EntityRepository versus the ServiceEntityRepository in Symfony. The author shares their experience of encountering a bug in a project and how they discovered that using a repository extending the EntityRepository instead of the ServiceEntityRepository was causing the issue. They explain that when an EntityManager encounters a driver exception during the flush operation, it closes and cannot be reopened. This means that if a repository extends the EntityRepository and encounters an exception, the EntityManager will remain closed for subsequent messages. On the other hand, if the repository extends the ServiceEntityRepository, the EntityManager will be reset before processing each message. The author emphasizes that using the ServiceEntityRepository is the recommended approach to avoid issues with the EntityManager being closed. This article serves as a reminder for Symfony developers to be mindful of the repository they choose when working with Doctrine.