I use pessimistic locking quite a lot in my application, and it works fine when using the Entity Manager:
$em->find($class, $id, LockMode::PESSIMISTIC_WRITE);
This results in a SELECT FOR UPDATE
when using MySQL.
Now I need to use the same locking but for entities retrieved with a DQL query.
Is it possible to use pessimistic locking in DQL?
Found the solution, using Query::setLockMode():
$query = $this->em->createQuery('SELECT ...');
$query->setLockMode(LockMode::PESSIMISTIC_WRITE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With