Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SELECT FOR UPDATE in Doctrine 2 DQL

Tags:

doctrine-orm

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?

like image 515
BenMorel Avatar asked Dec 19 '22 21:12

BenMorel


1 Answers

Found the solution, using Query::setLockMode():

$query = $this->em->createQuery('SELECT ...');
$query->setLockMode(LockMode::PESSIMISTIC_WRITE);
like image 179
BenMorel Avatar answered Mar 07 '23 19:03

BenMorel