mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Doctrine second level result caching not working with deep fetch join query #5598
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 @aimfeld on GitHub (Jul 4, 2017).
I have posted this question on stackoverflow here. It might be a doctrine bug (or a known limitation), so I hope it's okay if I ask here as well.
I have the following query in a doctrine repository:
The query fetches page objects, their group objects and the group label eagerly.
However, I get the following error:
It seems that doctrine cannot find the labelText association of the group object. When I remove
'groupLabelText'from the select clause, the query and the second level result caching work fine (but the group label objects are not fetched eagerly anymore). When I disable caching withsetCacheable(false), the query works fine.It seems that doctrine is unable to cache results of fetch join queries with joins of more than one level.
Is there a way to get this working? Or should I not use deep fetch join queries, and use lazy fetching for the joined objects? Entity and association second level caching works fine for me, so maybe the performance hit is not that bad. Also, the code would become easier, since the fetch join queries are quite complicated (I use up to 25 joins and elements in the select clause in real code).
@lcobucci commented on GitHub (Aug 6, 2017):
@aimfeld sorry for taking that long to get back to you... is this happening on
v2.5.xorv2.6.x-dev? We have some known bugs related to L2C onv2.5.xthat got fixed onv2.6.x-devonly (due to multiple reasons).If the issue still happens on
v2.6.x-dev, could you please send us a failing test case that reproduces that behaviour? It would help us a lot to identify and fix the issue you're describing.You can find examples on
388afb46d0/tests/Doctrine/Tests/ORM/Functional/Ticket@aimfeld commented on GitHub (Aug 6, 2017):
@lcobucci The problem occurs with
v2.5.6. I have now triedv2.6.x-devand I don't get the exception anymore. The query result can now be cached and retrieved properly.However, when I checked with the debugger I noticed that only the main objects (
page) and the object of the first join (pageGroup) are actually retrieved from the cached query result. The objects of the second join (groupLabelText) are only retrieved as proxy objects, they don't seem to be included in the cached query result. So I don't think there's a difference if I include'groupLabelText'in the select query.I have already removed the fetch join queries from my code. I guess they don't result in much of a performance gain anyway, if I have all the associations cached.
@lcobucci commented on GitHub (Aug 6, 2017):
@aimfeld that's kind of weird, all the associations - that are mapped as cached - should have been correctly fetched from the cache layer. Would it be possible to send PR that reproduces that scenario?
@aimfeld commented on GitHub (Aug 7, 2017):
@lcobucci I don't have the time to set up the environment and write a test right now, but here are my stripped down models, hope these help (I'm working with
MappedSuperclass):And this is the query:
@githoober commented on GitHub (Jun 27, 2018):
Since nobody responded and looked into the OP's issue, I see no point to present another use case, but essentially I have a similar issue, where a *ToOne association is incorrectly determined and passed to
\Doctrine\ORM\UnitOfWork::getEntityIdentifierwith an errorspl_object_hash() expects parameter 1 to be object, array given. I am on v2.6.@githoober commented on GitHub (Jun 28, 2018):
I filed a new issue for my case: https://github.com/doctrine/doctrine2/issues/7277