I know this is an old problem from Symfony2 / Doctrine2 throwing index error when flushing the entity manager, but the error still exists, and I have no idea what to do:
I have a Symfony-Command-Script, which inserts entities in a database. I'm using
PHP Version 5.6 symfony/symfony (v2.8.8) doctrine/orm (v2.5.4),
and the important part of the code is:
$em = $this->getContainer()->get('doctrine')->getManager();
$em->getConnection()->getConfiguration()->setSQLLogger(null);
// remove all listeners
foreach ($em->getEventManager()->getListeners() as $event => $listeners) {
foreach ($listeners as $listener) {
$em->getEventManager()->removeEventListener($event, $listener);
}
}
.....
foreach($importdateien as $importdatei) {
$em_batchSize = 0;
...
$em->persist($artikel); // article is an Symfony-Entity
$em_batchSize ++;
if (($em_batchSize % 20) === 0) {
$em->flush();
$em->clear(); // Detaches all objects from Doctrine!
$this->getContainer()->get('doctrine')->resetManager();
$em = $this->getContainer()->get('doctrine')->getManager();
}
}
And exactly after 20 inserts i got the error:
[ErrorException] Undefined index: 000000004c2a3e220000000066122f03
The are no remove or update statements in the loop. There are simple inserts
I think I have read several Pages with possible solutions, but nothing works.
The Schema is validated, there are no errors.