DDC-501: Merging entities that contained unloaded proxy collections will delete those associations #5008

doctrinebot opened this Issue Apr 8, 2010 · 7 comments

2 participants


Jira issue originally created by user markus.woessner:

If loading an entity without its -to-many-collections, detaching and merging it back WITHOUT having touched those associations will result in two strange behaviours:

oneToMany (bidrectional, mapped by loaded entity): After merge the collection remains empty. Flushing EM and reloading entity will reveal associated entities again

manyToMany (bidirectional, mapped by targeted entity): After merge the collection remains empty. Flushing EM will physically delete associations.

  • ----------------- !! NOTE !! --------------------
  • To reproduce the manyToMany-Bug it's necessary
  • to cascade "merge" on cmUser::groups
  • -------------------------------------------------

Comment created by markus.woessner:

Forgot to tell trunk revision


Comment created by shurakai:

This issue is mainly caused by the entity not being initialized before serialization. Additionally, the PersistenCollection does loose all information that is needed to regain the kept entities because the collection itself is not initialized before serialization.

I've added an initialization call here http://github.com/Shurakai/doctrine2/commit/6c185a2891111dfbd83d381bad8c5a2b16536cad#diff-0

However, I'm not sure whether this is the best solution. Any thoughts?


Comment created by romanb:

@Christian: I looked at the testcase you committed there and the assumptions it makes are not correct. The original test case provided by Markus made the right assumptions, that is, after the user is unserialized it can and should not know about its groups or phonenumbers since these were not serialized.
When you serialize an entity, you serialize a partial snapshot of its state. When you unserialize it you have all the state that was loaded prior to serialization but you can not get at the rest, the object is detached from the rest of the object graph. Thats where merge() comes in, it reattaches a detached entity to a managed environment where associations can be lazy-loaded, state changes are tracked, etc.

So the problem must come later, at the point of merging.


Comment created by romanb:

Pushing back to beta3.


Comment created by @beberlei:



Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.0-BETA3 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