skip to Main Content

In my Symfony app, I have a function that saves a record using Doctrine:

public function save(Car $car): void
{
    $this->getEntityManager()->persist($car);
    $this->getEntityManager()->flush($car);
}

But in recent days, I get a lot of log entries like this:

Calling DoctrineORMEntityManager::flush() with any arguments to
flush specific entities is deprecated and will not be supported in
Doctrine ORM 3.0.

What should I do instead?

2

Answers


  1. The deprecation warning indicates that passing specific entities to EntityManager::flush() is deprecated in Doctrine ORM and will be removed in version 3.0. Instead of flushing specific entities, you should call flush() without arguments. This flushes all pending changes in the persistence context managed by the EntityManager :

    public function save(Car $car): void
    {
        $entityManager = $this->getEntityManager();
        $entityManager->persist($car);
        $entityManager->flush(); // Flush all changes
    }
    
    Login or Signup to reply.
  2. There is a potential issue with the flush() method usage in Doctrine.
    It worked for me when I removed the $car parameter from flushing

    public function save(Car $car): void
    {
       $this->getEntityManager()->persist($car);
       $this->getEntityManager()->flush();
    

    }

    so it looks like passing an entity to flush() is not supported in newer versions of Doctrine and will produce an error

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search