since 2 weeks, we are having this problem while trying to flush new elements:
CRITICAL: Doctrine\ORM\ORMInvalidArgumentException:
A new entity was found through the relationship 'Comment#capture' that was not configured to cascade persist operations for entity
But the capture
is already in the database, and we are getting it by a findOneBy
, so if we cascade persist it, or persist it, we get a
Table constraint violation: duplicate entry.
The comments are created in a loop with differents captures, with a new, and all required field are set.
With all of the entities persisted and / or got by a findOne
(and all valid), the flush still fails.
I'm on this issue since a while, so please help me
In my case a too early call of
$this->entityManager->clear();
caused the problem. It also disappeared by only doing a clear on the recent object, like
$this->entityManager->clear($capture);
I had the same problem and it was the same EntityManager
. I wanted to insert an object related ManyToOne
. And I don't want a cascade
persist
.
Example :
$category = $em->find("Category", 10); $product = new Product(); $product->setCategory($category) $em->persist($product); $em->flush();
This throws the same exception for me.
So the solution is :
$category = $em->find("Category", 10); $product = new Product(); $product->setCategory($category) $em->merge($product); $em->flush();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With