DDC-3943: [GH-1531] fixed outdated entity #4822

Closed
opened 2026-01-22 14:49:59 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Oct 9, 2015).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user @doctrinebot:

This issue is created automatically through a Github pull request on behalf of messyOne:

Url: https://github.com/doctrine/doctrine2/pull/1531

Message:

I found an issue with outdated entities. If you have following code which will be called by your request:

$em->beginTransaction();
try {
    $repository = $em->getRepository(Entity::class);
    /*** @var Entity $entity **/
    $entity = $repository->findOneBy(['tyef' => 'foo']);
    $em->lock($entity, LockMode::PESSIMISTIC_WRITE);
    $entity->increase(1); //increase field 'bar'

    sleep(2);

    $em->persist($entity);

    $em->flush();
    $em->commit();
} catch (\Exception $e) {
    $em->rollback();
    throw $e;
}

This will happen:

  1. Before requests: Number is 30 (in fieldbar)
  2. Request 1 is fired
  3. Request 2 is fired
  4. Request 1 finished. Number is 31
  5. Request 2 finished. Number is _31_

Since we have a write lock inside of a transaction I expect to have _32_. The entity is not up to date and has do be refreshed.

Originally created by @doctrinebot on GitHub (Oct 9, 2015). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user @doctrinebot: This issue is created automatically through a Github pull request on behalf of messyOne: Url: https://github.com/doctrine/doctrine2/pull/1531 Message: I found an issue with outdated entities. If you have following code which will be called by your request: ``` $em->beginTransaction(); try { $repository = $em->getRepository(Entity::class); /*** @var Entity $entity **/ $entity = $repository->findOneBy(['tyef' => 'foo']); $em->lock($entity, LockMode::PESSIMISTIC_WRITE); $entity->increase(1); //increase field 'bar' sleep(2); $em->persist($entity); $em->flush(); $em->commit(); } catch (\Exception $e) { $em->rollback(); throw $e; } ``` This will happen: 1. Before requests: Number is 30 (in field`bar`) 2. Request 1 is fired 3. Request 2 is fired 4. Request 1 finished. Number is 31 5. Request 2 finished. Number is **_31**_ Since we have a write lock inside of a transaction I expect to have **_32**_. The entity is not up to date and has do be refreshed.
admin added the Bug label 2026-01-22 14:49:59 +01:00
admin closed this issue 2026-01-22 14:50:00 +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#4822