Object hash in UoW #6217

Open
opened 2026-01-22 15:29:02 +01:00 by admin · 0 comments
Owner

Originally created by @sweiguny on GitHub (Apr 9, 2019).

Originally assigned to: @Ocramius on GitHub.

Q A
Version doctrine/orm v2.6.3

Question

Hello,

I have some questions about the internals of Doctrine, which are primarily for my understanding.

The UnitOfWork has a collection of all entities under management and therefore also a list of their states (private $entityStates = [];). Here is an assignment of a new Entity. As you can see there, the object hash is taken as key and the value is the state ("managed").

Isn't somewhere the primary key of the entity checked, too?
Because, if only the object hash is checked, I can clone my entity which gives me another object hash, pass it to EntityManager::persist() and have basically the same entity twice in the UnitOfWork.

Or did I miss something?

Thank you in advance for your answer.

Originally created by @sweiguny on GitHub (Apr 9, 2019). Originally assigned to: @Ocramius on GitHub. | Q | A |------------ | ----- | Version | doctrine/orm v2.6.3 ### Question Hello, I have some questions about the internals of Doctrine, which are primarily for my understanding. The `UnitOfWork` has a collection of all entities under management and therefore also a list of their states (`private $entityStates = [];`). [Here is an assignment of a new Entity.](https://github.com/doctrine/orm/blob/ebb53acda96e304a6f91d4a5a2d76378a4e1d210/lib/Doctrine/ORM/UnitOfWork.php#L858) As you can see there, the object hash is taken as key and the value is the state ("managed"). **Isn't somewhere the primary key of the entity checked, too?** Because, if only the object hash is checked, I can clone my entity which gives me another object hash, pass it to `EntityManager::persist()` and have basically the same entity twice in the `UnitOfWork`. Or did I miss something? Thank you in advance for your answer.
admin added the Question label 2026-01-22 15:29:02 +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#6217