mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Identity Map Collision with Class Table Inheritance When Using Predefined IDs #7485
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 @juslintek on GitHub (Mar 7, 2025).
Description
When using Class Table Inheritance (CTI) with predefined IDs (e.g., from an external system) for internal representation, retrieving an entity via the parent class and then the child class causes an identity map collision. Doctrine creates a new instance instead of reusing the managed one, resulting in duplicate instances with the same ID in the Unit of Work.
Steps to Reproduce
BaseEntity(parent) andChildEntityA(child), using a predefined/external string ID.ChildEntityAinstance with a predefined ID.$em->find(BaseEntity::class, $externalId)– returnsChildEntityA.$em->find(ChildEntityA::class, $externalId)– creates a new instance.$em->flush(), which triggers an identity collision.Expected Behavior
The second
find()should return the existing managed instance from the UOW, even with predefined/external IDs.Actual Behavior
A new instance is created, causing an identity collision. This occurs specifically when using predefined IDs.
Environment
Using latest stable symfony 7.2.4
Using Api Platform: 3.4.16
Percona MySQL Database: 8.0.36
PHP: 8.3.17 under alpine linux
Reproducible Example
Additional Notes
This seems related to how the UOW manages identity mapping for CTI with predefined/external IDs when querying child classes directly.
@mpdude commented on GitHub (Apr 7, 2025):
I've tried to add a test case for this in #11901, but I fail to demonstrate the problem both on 2.20.x and 3.3x.