[PR #5578] Resolve associations cache key not part of ResultSetMapping #9651

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

Original Pull Request: https://github.com/doctrine/orm/pull/5578

State: closed
Merged: No


Yet another bug with 2nd level cache :) I cannot generate a proper test case (for now), so I try to explain the issue to sum up my change. This happens in 2.5, 2.5-dev and dev-master branches.

the bug

I set up a DQL query which use setCachable(true), and (almost) everything is configured to use 2nd level cache. While retrieving object from cache through the DefaultQueryCache, I got the following error:

Catchable Fatal Error: Object of class Doctrine\ORM\Cache\AssociationCacheEntry could not be converted to string
vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php at line 2676

The error is triggered by an AssociationCacheEntry which is left behind during entity hydration.

why it happen

I saw that in DefaultQueryCache the normal association cache resolution is overriden by ResultSetMapping resolution. This probably make sense, but the entity hydration is inlined (with a big TODO :) inside DefaultQueryCache, instead of using DefaultEntityHydrator.

I think that resolving only Rsm mapping is not enough. If the entity is cached through DefaultEntityHydrator::buildCacheEntry, there are also other association.

my fix

I cannot provide a proper solution for merging the Rsm logic into DefaultEntityHydrator, to get rid of the TODO. So I copied the relevant part to DefaultQueryCache, just to fix the issue for now.

**Original Pull Request:** https://github.com/doctrine/orm/pull/5578 **State:** closed **Merged:** No --- Yet another bug with 2nd level cache :) I cannot generate a proper test case (for now), so I try to explain the issue to sum up my change. This happens in `2.5`, `2.5-dev` and `dev-master` branches. ## the bug I set up a DQL query which use `setCachable(true)`, and (almost) everything is configured to use 2nd level cache. While retrieving object from cache through the `DefaultQueryCache`, I got the following error: ``` Catchable Fatal Error: Object of class Doctrine\ORM\Cache\AssociationCacheEntry could not be converted to string vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php at line 2676 ``` The error is triggered by an `AssociationCacheEntry` which is left behind during entity hydration. ## why it happen I saw that in `DefaultQueryCache` the normal association cache resolution is overriden by `ResultSetMapping` resolution. This probably make sense, but the entity hydration is inlined (with a big `TODO` :) inside `DefaultQueryCache`, instead of using `DefaultEntityHydrator`. I think that resolving only `Rsm` mapping is not enough. If the entity is cached through `DefaultEntityHydrator::buildCacheEntry`, there are also other association. ## my fix I cannot provide a proper solution for merging the Rsm logic into `DefaultEntityHydrator`, to get rid of the TODO. So I copied the relevant part to `DefaultQueryCache`, just to fix the issue for now.
admin added the pull-request label 2026-01-22 16:04:59 +01:00
admin closed this issue 2026-01-22 16:04:59 +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#9651