[DDC-875] Merge can sometimes add the same entity twice into a collection Created: 11/Nov/10  Updated: 19/May/15  Resolved: 11/Mar/12

Status: Closed
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.0-BETA4
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Dave Keen Assignee: Roman S. Borschel
Resolution: Cannot Reproduce Votes: 1
Labels: None

Attachments: File multipleaddmerge.diff     File multipleaddmerge2.diff    


When merging some cascade merge object-graphs, the same entity in a ManyToMany association can be put into a collection twice during doMerge.

The attached patch should stop this from happening.

Comment by Benjamin Eberlei [ 15/Nov/10 ]

which conditions lead to this problem? I want to write a test for it

Comment by Benjamin Eberlei [ 15/Nov/10 ]

not doint the unwrap() but add() directly was a bugfix for one of your other issues .Why is unwrap in here again?

Comment by Dave Keen [ 20/Dec/10 ]

Oops - that was a mistake. I have attached multipleaddmerge2.diff which no longer uses unwrap to add the element.

Comment by Benjamin Eberlei [ 27/Dec/10 ]

That is exactly the same code in the patch, the lines are just formatted differently.

Comment by Dave Keen [ 06/Jan/11 ]

Sorry, I am still getting the hang of git and diff and maybe what I put in there isn't what I meant to. I have now pushed the code to the DDC-875 branch on my ccapndave/doctrine2 fork on GitHub, hopefully this works better.

As far as I can tell I am using unwrap() in order to check whether the element already exists in the array, but then calling >add() directly on the PersistentCollection rather than the ArrayCollection, triggering $this>changed().

Comment by Benjamin Eberlei [ 26/Feb/11 ]

It seems even this issue is caused by multiple calls to persist. I cannot reproduce this with just a single bidirectional cascade merge.

Comment by Alexander [ 11/Mar/12 ]

We cannot reproduce this error and haven't had similar complaints ever-since. Feel free to open a new issue with a failing testcase.

Comment by Vivek Soni [ 19/May/15 ]

I am also facing this issue, I have String as primary key for a table (brand table) getting this error

A new entity was found through the relationship 'Application\Entity\Pcds#brandCode' that was not configured to cascade persist operations for entity: Company\Model\Entity\Brand@000000003beb6d2200007ffa52ab9a34. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade=


). If you cannot find out which entity causes the problem implement 'Company\Model\Entity\Brand#__toString()' to get a clue.

If i var_dump this $brand entity it shows that it have primary key inside it.

Comment by Vivek Soni [ 19/May/15 ]

This stackoverflow question solved my problem, instead of persist, i had to do merge


Generated at Fri Oct 09 12:16:20 EDT 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.