Hi there,

struggling trying to understand how the PESSIMISTIC_LOCK is working.

I have this code:

$this->getEntityManager()->getConnection()->beginTransaction();

$queryBuilder = $this->getEntityManager()->createQueryBuilder();
$query        = $queryBuilder
    ->select('foo')
    ->from(Foo::class, 'foo')
    ->where('foo.id = :fooId')
    ->setParameter('fooId', $fooId)
    ->getQuery();

$query->setLockMode(LockMode::PESSIMISTIC_WRITE);


inside my repository. 

If I try to do to update that row that I'm selecting with the lock during 
the transaction (so before the commit of the transaction), the lock works 
properly.

But if a try to SELECT the same row during the transaction, I'm not having 
any problem at retrieving data. I was expecting the same behaviour for read 
and write because of the doctrine documentation (here 
<http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/reference/transactions-and-concurrency.html#pessimistic-locking>
):

Pessimistic Write (Doctrine\DBAL\LockMode::PESSIMISTIC_WRITE), locks the 
underlying database rows for concurrent *Read and Write* Operations.


What am I missing?


-- 
*This email is sent according to our standard email disclaimer 
<https://www.lendinvest.com/disclosures/email-disclaimer/>.*

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to