mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Selecting the same alias twice results in "The given entity has no identity/no id values set. It cannot be added to the identity map." #7270
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 @isarastov on GitHub (Dec 1, 2023).
BC Break Report
EDIT
#11194 seems to resolve this issue.
My original assumption was that it's caused by the alias being selected twice, but this proved wrong. It's more probably caused by something in the result itself (at least this seems to be the case for me and @winiarekk)
Summary
After upgrading to 2.16.0 a query that was selecting the same alias twice started throwing the following exception:
Obviously the query shouldn't select the same alias twice, however this was working until 2.15.5.
I was able to identify the change that causes the different behavior as this one. If I add the 4 lines from 2.15.5 instead of the call to
registerManagedit works but I noticed that the$idHashis an empty string in this case.I also found this issue that seems related: #10889
Previous behavior
The Foo entity was hydrated successfully.
Current behavior
Doctrine\ORM\ORMInvalidArgumentException:
in doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php -> getIdHashByEntity
How to reproduce
I tried to reproduce this in a test case, but with no success. Anyway, here's a simplified version of the code that causes the error:
@winiarekk commented on GitHub (Mar 1, 2024):
I have the same issue after upgrading doctrine, however in my case there is definitely no duplicated select of the same alias. What's even more interesting, the hydration for the query works good if I change one parameter in it, so it seems to be somehow related to the data.
I was trying to figure out what's wrong, so I inspected the raw results of SQL between non-working and working queries. The only difference, I was able to observe, is that the failing query has only one row in the result, when the successful ones return at least few of them, but no idea if this is related.
EDIT:
This PR resolves my problem https://github.com/doctrine/orm/pull/11194
@isarastov commented on GitHub (Mar 1, 2024):
#11194 solves the issue for me too.
I also tested two cases without the fix - the first one returns 4 rows (for the same Foo) and it works, the other returns 39 rows (again, for the same Foo) and it fails. So this probably has nothing to do with the multiple selects.
@alexander-schranz commented on GitHub (Jun 27, 2024):
https://github.com/doctrine/orm/pull/11194 is merged so this may also be resolved?