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

Closed
doctrinebot opened this Issue Nov 11, 2010 · 11 comments

1 participant

@doctrinebot

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.

@doctrinebot

Comment created by @beberlei:

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

@doctrinebot

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

Comment created by ccapndave:

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

@doctrinebot

Comment created by @beberlei:

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

@doctrinebot

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

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

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

Issue was closed with resolution "Cannot Reproduce"

@doctrinebot

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

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 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