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

Closed
doctrinebot opened this Issue Jan 11, 2012 · 2 comments

2 participants

@doctrinebot

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();
}

@doctrinebot

Comment created by @beberlei:

Fixed and merged into 2.2 and 2.1

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.1.6 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment