I am trying to do some Bulk inserts into my database. I have read the article about it on the doctrine side and wanted to use sporadic flushs and clears in order to prevent high memory consumptions. Unfortunately all entities get detached in the process, not only the ones I am inserting, but also the relations to it.
I tried to remerge them or use references instead. In my current case I am using a reference and still I get the following error message:
[Doctrine\ORM\ORMInvalidArgumentException]
A new entity was found through the relationship 'Strego\TippBundle\Entity\Bet#betRound' that was not configured to cascade persist operations for entity: LoadTest GameGroup. 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"}).
The relevant coding is this:
// BetRound
print(PHP_EOL."Search for BetROund");
$betRounds = $em->getRepository('StregoTippBundle:BetRound')->findAll();
print(PHP_EOL.'found Betrrounds:'.count($betRounds));
$betRound = current($betRounds);
...
// References
$betRoundRef = $em->getReference('Strego\\TippBundle\\Entity\\BetRound', $betRound->getId());
and here the insert:
foreach($gameRefs as $game){
$bet = new GameBet();
$bet->setBetround($betRoundRef);
$bet->setUser($genuser);
$bet->setGame($game);
$bet->setScoreT1($this->getScore());
$bet->setScoreT2($this->getScore());
$bet->recalculatePoints();
$em->persist($bet);
}
if(($i % self::$batchSize) == 0){
$em->persist($userGroup);
$em->persist($mySelf);
$em->flush();
$em->clear();
$em->merge($betRound);
$em->merge($userGroup);
$em->merge($mySelf);
}
My whole Fixture for loading this data can be found here: https://gist.github.com/KeKs0r/a3006768db267311bb35