DDC-1594: Merging serialized entity back to the UnitOfWork #2001

Closed
opened 2026-01-22 13:37:13 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Jan 11, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user mrkanister:

(I'm using doctrine 2.1.4.)

I'm trying to merge an Entity back to the UnitOfWork.
The Entity is created from a serialized object (The deserialzed Entity is a valid Entity Object. The only difference
is that it is not managed by Doctrine yet) and I'm using the merge
method of the EntityManager to get it in managed state again.

This results in a call of the Method doMerge() in the UnitOfWork
class.
This method takes the id of my deserialized Entity, that I want to
merge, and looks if an Entity with that id is already in doctrine
cache. If that is the case my deserialized Entity is merged with the
one in the cache. So far so good. But I've got the Problem, that the
Entity, which is in cache, is not initialized yet. It is not initialized because
this Entity has a relation to another Entity that a used earlier in code.
It's there but in uninitialized stat, because I did not access it yet.
So when my deserialized Entity and the one from cache gets merged, some field are
uninitialized (the id field, for example).

I fixed the problem by adding this piece of code in line 1446 in the
UnitOfWork class:
if(! $managedCopy->isInitialized){
$managedCopy->**load();
}

Originally created by @doctrinebot on GitHub (Jan 11, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user mrkanister: (I'm using doctrine 2.1.4.) I'm trying to merge an Entity back to the UnitOfWork. The Entity is created from a serialized object (The deserialzed Entity is a valid Entity Object. The only difference is that it is not managed by Doctrine yet) and I'm using the merge method of the EntityManager to get it in managed state again. This results in a call of the Method doMerge() in the UnitOfWork class. This method takes the id of my deserialized Entity, that I want to merge, and looks if an Entity with that id is already in doctrine cache. If that is the case my deserialized Entity is merged with the one in the cache. So far so good. But I've got the Problem, that the Entity, which is in cache, is not initialized yet. It is not initialized because this Entity has a relation to another Entity that a used earlier in code. It's there but in uninitialized stat, because I did not access it yet. So when my deserialized Entity and the one from cache gets merged, some field are uninitialized (the id field, for example). I fixed the problem by adding this piece of code in line 1446 in the UnitOfWork class: if(! $managedCopy->__isInitialized__){ $managedCopy->**load(); }
admin added the Bug label 2026-01-22 13:37:13 +01:00
admin closed this issue 2026-01-22 13:37:13 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jan 15, 2012):

Comment created by @beberlei:

Fixed and merged into 2.2 and 2.1

@doctrinebot commented on GitHub (Jan 15, 2012): Comment created by @beberlei: Fixed and merged into 2.2 and 2.1
Author
Owner

@doctrinebot commented on GitHub (Jan 15, 2012):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Jan 15, 2012): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2001