Allow to lock entity with EntityManager#refresh() #7038

Closed
opened 2026-01-22 15:43:32 +01:00 by admin · 0 comments
Owner

Originally created by @michnovka on GitHub (Sep 11, 2022).

Feature Request

Recently I stumbled upon how useless the EntityManager#lock() method is in scenarios where you need up-to-date data during transaction.

Now the way to go is to use $entity = $em->find($entity->id, LockMode::PESSIMISTIC_WRITE);

It would be nice and more readable if we would allow to call EntityManager#refresh() and specify lockMode to acquire a lock on already loaded entity whilst making sure we have the latest version of it at runtime.

Q A
New Feature yes
RFC no
BC Break no

Summary

I would like to extend the EntityManager#refresh() to:

public function refresh($entity, $lockMode = null)

This will require similar change to UnitOfWork#refresh() signature, but otherwise should be a simple feature to implement.

What do you think?

Originally created by @michnovka on GitHub (Sep 11, 2022). ### Feature Request Recently I stumbled upon how [useless](https://stackoverflow.com/questions/73665780/when-does-entitymanagerlock-even-have-sense) the `EntityManager#lock()` method is in scenarios where you need up-to-date data during transaction. Now the way to go is to use `$entity = $em->find($entity->id, LockMode::PESSIMISTIC_WRITE);` It would be nice and more readable if we would allow to call `EntityManager#refresh()` and specify lockMode to acquire a lock on already loaded entity whilst making sure we have the latest version of it at runtime. | Q | A |------------ | ------ | New Feature | yes | RFC | no | BC Break | no #### Summary I would like to extend the `EntityManager#refresh()` to: ```php public function refresh($entity, $lockMode = null) ``` This will require similar change to `UnitOfWork#refresh()` signature, but otherwise should be a simple feature to implement. What do you think?
admin closed this issue 2026-01-22 15:43:32 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7038