mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
[Question] Optimistic Locking behaviour for dirty entities #5842
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @tavlima on GitHub (Jan 11, 2018).
I was surprised to see that
Doctrine\ORM\EntityManager::findis able to find an entity matching thelockVersionconstraint, even when the changes were not persisted yet.I get that the
findis optimised to check the identity map first, before hitting the database, but is there a reason do that even when explicitly locking?Couldn't we check if the identity mapped entity is not dirty and, only in that case, return from there and correctly short-circuit the DB query? I really think the current behaviour can be misleading in some scenarios...
@beberlei commented on GitHub (Dec 7, 2020):
But the entity manager is responsible for the entity and it has it in version 2. I think this behavior is correct.