mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Child entity not retrieved from array cache #6379
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @peterkeatingie on GitHub (Jan 3, 2020).
Bug Report
BC Break | no
Version | 2.7.0
Summary
Entity which is extended from a base class is not retrieved from array cache when using the second level cache.
ZF3 application.
Current behavior
Base class is abstract, with extending class as a child, using single table inheritance and second level cache.
When retrieving the child class using the findBy repository method, calls subsequent to the first one are not found in the cache. The entity is fetched from the database each time.
It looks to me like the entity is put into the cache with a key which is based on its child name but retrieval is attempted using the base class name.
How to reproduce
Entity definitions:
Base class:
Child class. Here the cache usage is set:
Doctrine configuration:
Calling fetch several times leads to a new db call each time (this is BaseChild repo):
Query log:
During debugging, I see that the entity is put into the array cache after the first call to the repository with the following key:
DoctrineModule:gts_base_entity_basechild[gts_base_entity_basechild_gts.base.entity.basechild_1][1]But when retrieving the following key is used to find the entry:
DoctrineModule:gts_base_entity_basechild[gts_base_entity_basechild_gts.base.entity.base_1][1]The reason for this is that in Doctrine\ORM\Cache\DefaultQueryCache::put (line 284) the cache key comes from the found entity however the key to retrieve comes from the root entity name in Doctrine\ORM\Cache\DefaultQueryCache::get (line 121).
Expected behavior
The second call to the repository should get the entity from the cache instead of making another query on the DB.
Of course it's possible that I'm missing some configuration and this may be expected as I have it configured - in which case any guidance regarding the configuration would be much appreciated.
This works as I would expect on any entity which does not have a base class.
@peterkeatingie commented on GitHub (Jan 28, 2020):
Hi all, just checking to see if you had a chance to look at this since? Do you think it might be a bug?
Thanks,
Peter.
@SenseException commented on GitHub (Jan 28, 2020):
It was already labelled as a bug. Do you feel like you want to try to fix it in a pull request?
@peterkeatingie commented on GitHub (Jan 29, 2020):
Sure, let me see what I can do, thanks.
@peterkeatingie commented on GitHub (Feb 2, 2020):
PR: https://github.com/doctrine/orm/pull/8009
@peterkeatingie commented on GitHub (Feb 15, 2020):
New PR against 2.7 https://github.com/doctrine/orm/pull/8023
@beberlei commented on GitHub (Mar 1, 2020):
Fixed by #8023