ORM second level cache and version (locking) #5886

Closed
opened 2026-01-22 15:21:13 +01:00 by admin · 7 comments
Owner

Originally created by @wtorsi on GitHub (Feb 15, 2018).

Originally assigned to: @wtorsi on GitHub.

Hi,
I have found strange behaviour when using Second Level Cache and Version.
When new version is set second level cache does not include it into update.

After some investigation:
The problem occurs here DefaultEntityHydrator::buildCacheEntry, UnitOfWork does not include version field in actualData.

Any ideas how to fix it?

Originally created by @wtorsi on GitHub (Feb 15, 2018). Originally assigned to: @wtorsi on GitHub. Hi, I have found strange behaviour when using Second Level Cache and Version. When new version is set second level cache does not include it into update. After some investigation: The problem occurs here `DefaultEntityHydrator::buildCacheEntry`, UnitOfWork does not include version field in actualData. Any ideas how to fix it?
admin added the BugMissing Tests labels 2026-01-22 15:21:13 +01:00
admin closed this issue 2026-01-22 15:21:13 +01:00
Author
Owner

@Ocramius commented on GitHub (Feb 15, 2018):

This is way too little information to work on anything. Please try re-creating a failure with an isolated test. See examples at https://github.com/doctrine/doctrine2/tree/master/tests/Doctrine/Tests/ORM/Functional/Ticket

@Ocramius commented on GitHub (Feb 15, 2018): This is way too little information to work on anything. Please try re-creating a failure with an isolated test. See examples at https://github.com/doctrine/doctrine2/tree/master/tests/Doctrine/Tests/ORM/Functional/Ticket
Author
Owner

@wtorsi commented on GitHub (Feb 15, 2018):

I have never done it before.
Also, i'm using Symfony Bridge, I have never configured Doctrine from the box :)
Ok, i'll try.

Here is the fast fix:

// Doctrine\ORM\Cache\DefaultEntityHydrator::buildCacheEntry

$data = $this->uow->getOriginalEntityData($entity);
$data = array_merge($data, $metadata->getIdentifierValues($entity)); // why update has no identifier values ?

//here it is
if ($metadata->isVersioned) {
    $data[$metadata->versionField] = $metadata->getFieldValue($entity, $metadata->versionField);
}

This can fix the problem.

@wtorsi commented on GitHub (Feb 15, 2018): I have never done it before. Also, i'm using Symfony Bridge, I have never configured Doctrine from the box :) Ok, i'll try. Here is the fast fix: ``` // Doctrine\ORM\Cache\DefaultEntityHydrator::buildCacheEntry $data = $this->uow->getOriginalEntityData($entity); $data = array_merge($data, $metadata->getIdentifierValues($entity)); // why update has no identifier values ? //here it is if ($metadata->isVersioned) { $data[$metadata->versionField] = $metadata->getFieldValue($entity, $metadata->versionField); } ``` This can fix the problem.
Author
Owner

@wtorsi commented on GitHub (Feb 16, 2018):

@Ocramius hi again, I need some help.
How I can push a commit with test to repo? It's my first time, sorry.

@wtorsi commented on GitHub (Feb 16, 2018): @Ocramius hi again, I need some help. How I can push a commit with test to repo? It's my first time, sorry.
Author
Owner

@Ocramius commented on GitHub (Feb 16, 2018):

@wtorsi you first need to fork this repository (top right on this page), then follow https://yangsu.github.io/pull-request-tutorial/ 👍

@Ocramius commented on GitHub (Feb 16, 2018): @wtorsi you first need to fork this repository (top right on this page), then follow https://yangsu.github.io/pull-request-tutorial/ 👍
Author
Owner

@wtorsi commented on GitHub (Feb 16, 2018):

Thank's

@wtorsi commented on GitHub (Feb 16, 2018): Thank's
Author
Owner

@wtorsi commented on GitHub (Feb 16, 2018):

Got it, here is the test.
Here is the test and fix for doctrine 3

@wtorsi commented on GitHub (Feb 16, 2018): Got it, here is the test. Here is the test and fix for doctrine 3
Author
Owner

@lcobucci commented on GitHub (Feb 17, 2018):

Fixed by #7069

@lcobucci commented on GitHub (Feb 17, 2018): Fixed by #7069
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5886