1

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.

Community
  • 1
  • 1
Bueck0815
  • 193
  • 8
  • Batch-file tag refers to Windows' oldest shell language and has nothing to do with databases. –  Jul 22 '16 at 07:08
  • ups - sorry, I have removed this tag. – Bueck0815 Jul 22 '16 at 07:10
  • 1
    Why are you doing the resetManager/getManager? I don't see any really need for them. At the very least, comment them out and see what happens. – Cerad Jul 22 '16 at 11:45
  • The "resetManager/getManage" was only a try - when I comment this out, the problem still exists. When I comment out the "$em->clear()", the script works fine, but after a few thousand inserts it becomes very very slow. – Bueck0815 Jul 22 '16 at 13:45

0 Answers0