Calling Doctrine\ORM\EntityManager::clear() with any arguments to clear specific entities is deprecated #6354

Closed
opened 2026-01-22 15:31:37 +01:00 by admin · 5 comments
Owner

Originally created by @ruudk on GitHub (Nov 26, 2019).

Originally assigned to: @lcobucci on GitHub.

Bug Report

Q A
BC Break no
Version 2.7.0

Summary

Calling Doctrine\ORM\EntityRepository::clear triggers deprecation message:

User Deprecated: Calling Doctrine\ORM\EntityManager::clear() with any arguments to clear specific entities is deprecated and will not be supported in Doctrine ORM 3.0. {"exception":"[object] (ErrorException(code: 0): User Deprecated: Calling Doctrine\\ORM\\EntityManager::clear() with any arguments to clear specific entities is deprecated and will not be supported in Doctrine ORM 3.0. at /var/www/app/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:562)"} []

Current behavior

Doctrine\ORM\EntityRepository::clear does not any input and passes the call to $this->_em->clear($this->_class->rootEntityName);.

I think we can just remove the $this->_class->rootEntityName argument here:
a416a9a8b2/lib/Doctrine/ORM/EntityRepository.php (L133-L136)

Originally created by @ruudk on GitHub (Nov 26, 2019). Originally assigned to: @lcobucci on GitHub. ### Bug Report | Q | A |------------ | ------ | BC Break |no | Version | 2.7.0 #### Summary Calling `Doctrine\ORM\EntityRepository::clear` triggers deprecation message: ``` User Deprecated: Calling Doctrine\ORM\EntityManager::clear() with any arguments to clear specific entities is deprecated and will not be supported in Doctrine ORM 3.0. {"exception":"[object] (ErrorException(code: 0): User Deprecated: Calling Doctrine\\ORM\\EntityManager::clear() with any arguments to clear specific entities is deprecated and will not be supported in Doctrine ORM 3.0. at /var/www/app/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:562)"} [] ``` #### Current behavior `Doctrine\ORM\EntityRepository::clear` does not any input and passes the call to `$this->_em->clear($this->_class->rootEntityName);`. I think we can just remove the `$this->_class->rootEntityName` argument here: https://github.com/doctrine/orm/blob/a416a9a8b2cd2ea0f7b7b5638986e8b398f34df8/lib/Doctrine/ORM/EntityRepository.php#L133-L136
admin added the Deprecation label 2026-01-22 15:31:37 +01:00
admin closed this issue 2026-01-22 15:31:37 +01:00
Author
Owner

@lcobucci commented on GitHub (Nov 26, 2019):

Related to #7922. I think this method should just be removed instead of removing the argument.

@lcobucci commented on GitHub (Nov 26, 2019): Related to #7922. I think this method should just be removed instead of removing the argument.
Author
Owner

@ruudk commented on GitHub (Nov 27, 2019):

Instead of doing that, shouldn't we just remove the argument for now to fix the deprecation? People that upgrade will get this deprecation now with no way to fix it.

Also, why should that method be removed? To me, it's handy to call clear on repository without having to do repo->getEntityManager->clear.

@ruudk commented on GitHub (Nov 27, 2019): Instead of doing that, shouldn't we just remove the argument for now to fix the deprecation? People that upgrade will get this deprecation now with no way to fix it. Also, why should that method be removed? To me, it's handy to call clear on repository without having to do repo->getEntityManager->clear.
Author
Owner

@Ocramius commented on GitHub (Nov 27, 2019):

Mostly needs to go because it is not up to a repository to control the UnitOfWork state.

@Ocramius commented on GitHub (Nov 27, 2019): Mostly needs to go because it is not up to a repository to control the `UnitOfWork` state.
Author
Owner

@lcobucci commented on GitHub (Nov 27, 2019):

Instead of doing that, shouldn't we just remove the argument for now to fix the deprecation? People that upgrade will get this deprecation now with no way to fix it.

That would be a behavioural bc break, which is not really good (as we've seen in v2.6.5).

Also, why should that method be removed? To me, it's handy to call clear on repository without having to do repo->getEntityManager->clear.

To me, we twisted the repository pattern with methods like that in this class.

The general idea of acting as an in-memory domain object collection is broken when my collection is still full of objects after I call clear().

Apart from that, it gives control over the identity map to components that should be completely unaware of it - harming encapsulation and leaking persistence details.

@lcobucci commented on GitHub (Nov 27, 2019): > Instead of doing that, shouldn't we just remove the argument for now to fix the deprecation? People that upgrade will get this deprecation now with no way to fix it. That would be a behavioural bc break, which is not really good (as we've seen in v2.6.5). > Also, why should that method be removed? To me, it's handy to call clear on repository without having to do repo->getEntityManager->clear. To me, we twisted the [repository pattern](https://martinfowler.com/eaaCatalog/repository.HTML) with methods like that in this class. The general idea of acting as an in-memory domain object collection is broken when my collection is still full of objects after I call `clear()`. Apart from that, it gives control over the identity map to components that should be completely unaware of it - harming encapsulation and leaking persistence details.
Author
Owner

@lcobucci commented on GitHub (Dec 9, 2019):

Handled by #7928

@lcobucci commented on GitHub (Dec 9, 2019): Handled by #7928
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6354