DDC-875: Merge can sometimes add the same entity twice into a collection #1086

Closed
opened 2026-01-22 13:01:28 +01:00 by admin · 11 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 11, 2010).

Jira issue originally created by user ccapndave:

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.

Originally created by @doctrinebot on GitHub (Nov 11, 2010). Jira issue originally created by user ccapndave: 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.
admin added the Bug label 2026-01-22 13:01:28 +01:00
admin closed this issue 2026-01-22 13:01:28 +01:00
Author
Owner

@doctrinebot commented on GitHub (Nov 15, 2010):

Comment created by @beberlei:

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

@doctrinebot commented on GitHub (Nov 15, 2010): Comment created by @beberlei: which conditions lead to this problem? I want to write a test for it
Author
Owner

@doctrinebot commented on GitHub (Nov 15, 2010):

Comment created by @beberlei:

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

@doctrinebot commented on GitHub (Nov 15, 2010): Comment created by @beberlei: not doint the unwrap() but add() directly was a bugfix for one of your other issues .Why is unwrap in here again?
Author
Owner

@doctrinebot commented on GitHub (Dec 20, 2010):

Comment created by ccapndave:

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

@doctrinebot commented on GitHub (Dec 20, 2010): Comment created by ccapndave: Oops - that was a mistake. I have attached multipleaddmerge2.diff which no longer uses unwrap to add the element.
Author
Owner

@doctrinebot commented on GitHub (Dec 27, 2010):

Comment created by @beberlei:

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

@doctrinebot commented on GitHub (Dec 27, 2010): Comment created by @beberlei: That is exactly the same code in the patch, the lines are just formatted differently.
Author
Owner

@doctrinebot commented on GitHub (Jan 6, 2011):

Comment created by ccapndave:

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().

@doctrinebot commented on GitHub (Jan 6, 2011): Comment created by ccapndave: 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](http://www.doctrine-project.org/jira/browse/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().
Author
Owner

@doctrinebot commented on GitHub (Feb 26, 2011):

Comment created by @beberlei:

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

@doctrinebot commented on GitHub (Feb 26, 2011): Comment created by @beberlei: It seems even this issue is caused by multiple calls to persist. I cannot reproduce this with just a single bidirectional cascade merge.
Author
Owner

@doctrinebot commented on GitHub (Mar 11, 2012):

Comment created by @asm89:

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

@doctrinebot commented on GitHub (Mar 11, 2012): Comment created by @asm89: We cannot reproduce this error and haven't had similar complaints ever-since. Feel free to open a new issue with a failing testcase.
Author
Owner

@doctrinebot commented on GitHub (Mar 11, 2012):

Issue was closed with resolution "Cannot Reproduce"

@doctrinebot commented on GitHub (Mar 11, 2012): Issue was closed with resolution "Cannot Reproduce"
Author
Owner

@doctrinebot commented on GitHub (May 19, 2015):

Comment created by viveksoni.net:

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={"persist"}). 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.

@doctrinebot commented on GitHub (May 19, 2015): Comment created by viveksoni.net: 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={"persist"}). 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.
Author
Owner

@doctrinebot commented on GitHub (May 19, 2015):

Comment created by viveksoni.net:

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

http://stackoverflow.com/questions/18215975/doctrine-a-new-entity-was-found-through-the-relationship

@doctrinebot commented on GitHub (May 19, 2015): Comment created by viveksoni.net: This stackoverflow question solved my problem, instead of persist, i had to do merge http://stackoverflow.com/questions/18215975/doctrine-a-new-entity-was-found-through-the-relationship
Author
Owner

@doctrinebot commented on GitHub (Dec 13, 2015):

Imported 2 attachments from Jira into https://gist.github.com/18f1290b429fd4a8ec35

@doctrinebot commented on GitHub (Dec 13, 2015): Imported 2 attachments from Jira into https://gist.github.com/18f1290b429fd4a8ec35 - [10859_multipleaddmerge.diff](https://gist.github.com/18f1290b429fd4a8ec35#file-10859_multipleaddmerge-diff) - [10897_multipleaddmerge2.diff](https://gist.github.com/18f1290b429fd4a8ec35#file-10897_multipleaddmerge2-diff)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1086