symfony2 doctrine2 batch processing error with entity

Lukas Lukac

i am trying to insert a lot of entities to DB. When i try to insert to example 5 entities with this code it works without problem... but when i implemented the batch method there it causes this error:

(code)

        if (!empty($invite_this_peopleArray)) {
            $batchSize = 20;
            $i = 0;
            foreach ($explodeInviteArray as $explodingUser) {
                ++$i;

                $notifiedUser=$userRepo->find($explodingUser);

                $notify=new Notify();
                $notify->setNotifyUser($user);
                $notify->setUser($notifiedUser);
                $notify->setStatus($lastStatus);
                $notify->setTyp('invite');
                $notify->setViewed(false);
                $notify->setAdInfo($name);

                $em->persist($notify);

                if (($i % $batchSize) === 0) {
                    $em->flush();
                    $em->clear(); // Detaches all objects from Doctrine!
                }            
            }
        }

Error:

A new entity was found through the relationship 'TB\NotifyBundle\Entity\Notify#notifyUser' that was not configured to cascade persist operations for entity: (nick of notify user user($user->getUsername())). 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"}).

What is the problem please?

BTW: when i modified the code so i clear only $notify and $notifiedUser like:

                if (($i % $batchSize) === 0) {
                    $em->flush();
                    $em->clear($notify); // Detaches all objects from Doctrine!
                    $em->clear($notifiedUser); // Detaches all objects from Doctrine!
                }   

The error is gone but i try to insert 4000 rows and i am getting insted this error:

Fatal error: Maximum execution time of 30 seconds exceeded in vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 514

When i try insert 1000 rows.

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes)

(so there is somewhere memory leak? )

Ken Hannel

It looks like the issue is coming from this line. It would appear the the $user Object is not a managed Doctrine Entity.

$notify->setNotifyUser($user);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

symfony2 doctrine2 batch processing error with entity

From Dev

symfony2 doctrine2: addselect elements to existing entity

From Dev

Register Doctrine2 entity listener as service in Symfony2

From Dev

Symfony2, Doctrine2, Entity Mapping

From Dev

symfony2 doctrine2 not flushing new entity

From Dev

Symfony2, Doctrine2, Entity Mapping

From Dev

Query with Criteria Exception error in doctrine2,Symfony2

From Dev

Doctrine2 entity creation error : "Could not find driver"

From Dev

Doctrine2 Entity Namespace

From Dev

Entity Not Found error in symfony2 Form

From Dev

The mappings //Entity and //Entity are inconsistent with each other - Symfony2/Doctrine2

From Dev

Symfony2 / Doctrine2 : how to access an entity annotation mapping?

From Dev

Doctrine2 Symfony2 extending entity in different bundle but with same database table name

From Dev

How to make query & result cache working for query of associated entity in Symfony2 and Doctrine2?

From Dev

Doctrine2 and Symfony2 - Best practice to use types for a specific entity

From Dev

symfony2 doctrine2: remove entity class from which was used in the past migrations

From Dev

Doctrine2 cascade entity creation

From Dev

Skip persisting of a related entity in Doctrine2

From Dev

How to find entity in doctrine2

From Dev

Skip persisting of a related entity in Doctrine2

From Dev

Doctrine2 @ORM in entity mapping annotation

From Dev

Doctrine2 Entity Custom Joining

From Dev

Some logic in Doctrine2 Entity

From Dev

Symfony2, Doctrine2 Found entity of type Doctrine\Common\Collections\ArrayCollection on association sth#category, but expecting sth

From Dev

Symfony2 Doctrine entity not hydrated

From Dev

Symfony2 and Doctrine entity undefined method

From Dev

Symfony2 and Doctrine entity undefined method

From Dev

doctrine symfony2 Error: Class Cocina\ComprasBundle\Entity\Productos has no association named proveedores

From Dev

CodeIgniter to Symfony2 with Doctrine2

Related Related

  1. 1

    symfony2 doctrine2 batch processing error with entity

  2. 2

    symfony2 doctrine2: addselect elements to existing entity

  3. 3

    Register Doctrine2 entity listener as service in Symfony2

  4. 4

    Symfony2, Doctrine2, Entity Mapping

  5. 5

    symfony2 doctrine2 not flushing new entity

  6. 6

    Symfony2, Doctrine2, Entity Mapping

  7. 7

    Query with Criteria Exception error in doctrine2,Symfony2

  8. 8

    Doctrine2 entity creation error : "Could not find driver"

  9. 9

    Doctrine2 Entity Namespace

  10. 10

    Entity Not Found error in symfony2 Form

  11. 11

    The mappings //Entity and //Entity are inconsistent with each other - Symfony2/Doctrine2

  12. 12

    Symfony2 / Doctrine2 : how to access an entity annotation mapping?

  13. 13

    Doctrine2 Symfony2 extending entity in different bundle but with same database table name

  14. 14

    How to make query & result cache working for query of associated entity in Symfony2 and Doctrine2?

  15. 15

    Doctrine2 and Symfony2 - Best practice to use types for a specific entity

  16. 16

    symfony2 doctrine2: remove entity class from which was used in the past migrations

  17. 17

    Doctrine2 cascade entity creation

  18. 18

    Skip persisting of a related entity in Doctrine2

  19. 19

    How to find entity in doctrine2

  20. 20

    Skip persisting of a related entity in Doctrine2

  21. 21

    Doctrine2 @ORM in entity mapping annotation

  22. 22

    Doctrine2 Entity Custom Joining

  23. 23

    Some logic in Doctrine2 Entity

  24. 24

    Symfony2, Doctrine2 Found entity of type Doctrine\Common\Collections\ArrayCollection on association sth#category, but expecting sth

  25. 25

    Symfony2 Doctrine entity not hydrated

  26. 26

    Symfony2 and Doctrine entity undefined method

  27. 27

    Symfony2 and Doctrine entity undefined method

  28. 28

    doctrine symfony2 Error: Class Cocina\ComprasBundle\Entity\Productos has no association named proveedores

  29. 29

    CodeIgniter to Symfony2 with Doctrine2

HotTag

Archive