ERROR - Notice: Undefined index: 000000004fc9e3630000000009549173 #6297

Open
opened 2026-01-22 15:30:20 +01:00 by admin · 9 comments
Owner

Originally created by @sinner on GitHub (Sep 15, 2019).

Originally assigned to: @sinner on GitHub.

Bug Report

Q A
BC Break yes
Version 2.6.1

Summary

Current behavior

Hi Symfony Community! Thank you very much in advance.

I have an API that receives a CSV file to import some registers but this task is queued using Amazon SQS, so it's an asynchronous task made using the Symfony Console Component who is loading that data.

This command-line application made using the Symfony Console Component uses Doctrine to store all registers read from that CSV file, so when it starts the first register is loaded perfectly into my PostgreSQL (AWS-RDS) database, but after that first register the next tries aren't loaded to the database giving the following exception "Undefined index: 000000004fc9e3630000000009549173", just after executing flush here is a bit of the track-trace of the exception:

...
"exceptionMessage" => "Notice: Undefined index: 000000004fc9e3630000000009549173"
  "exceptionTrace" => array:19 [
    0 => array:6 [
      "file" => "/srv/api/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php"
      "line" => 677
      "function" => "getEntityIdentifier"
      "class" => "Doctrine\ORM\UnitOfWork"
      "type" => "->"
      "args" => array:1 [
        0 => Proxies\__CG__\App\Entity\Member {#9112
          +__isInitialized__: false
          -id: 1
          -firstName: null
          -lastName: null
          -birthDate: null
          -profilePictureUrl: null
          -occupation: null
          -stateText: null
          -stateIsoCode: null
          -cityText: null
          -postalCode: null
          -referenceAddress: null
          -deceasedAt: null
          -status: null
          -roles: null
          -user: App\Entity\User {#9103
            #id: 2315
            #publicId: "ac41571d1fcbb25901b6ad030623abccfd8390fc"
            #username: "admin"
            #displayName: "Cory Taylor"
            #email: "teramailtest+admin@gmail.com"
            -temporaryOrgAdmin: false
            -alreadyHasGroupAdminRole: true
            -alreadyHasOrgAdminRole: true
            -birthdaysThisWeek: true
            -newMessageReplies: true
            -groupActivityStatus: true
            -hasEmail: false
            -mainRole: ""
            -realMainRole: ""
            #displayEmail: null
            #createdAt: DateTime @1568315992 {#13576
              date: 2019-09-12 19:19:52.971833 UTC (+00:00)
            }
            #roles: array:5 [
              0 => "ROLE_ADMIN"
              1 => "ROLE_SUPER_ADMIN"
              2 => "ROLE_ORGANIZATION_ADMIN"
              3 => "ROLE_EVA_GROUP_ADMIN"
              4 => "ROLE_EVA_MEMBER"
            ]
            #updatedAt: DateTime @1568315992 {#13576}
            #member: Proxies\__CG__\App\Entity\Member {#9112 …2}
            -languagePreference: Proxies\__CG__\App\Entity\Language {#9107
              +__isInitialized__: false
              -id: 40
              -name: null
              -iso: null
              -flag: null
              -enable: null
              #publicId: null
              #createdBy: null
              #updatedBy: null
              #dateCreated: null
              +referenceProxies: []
              #createdAt: null
              #updatedAt: null
               …2
            }
            -isVerifiedEmail: false
            #plainPassword: null
            #isIncomplete: null
            #mpaToken: null
            #mpaUserId: 166989
            +referenceProxies: []
            -termAndConditionAcceptances: Doctrine\ORM\PersistentCollection {#9108
              -snapshot: []
              -owner: App\Entity\User {#9103}
              -association: array:15 [ …15]
              -em: Doctrine\ORM\EntityManager {#224 …11}
              -backRefFieldName: "acceptedBy"
              -typeClass: Doctrine\ORM\Mapping\ClassMetadata {#8525 …}
              -isDirty: false
              #collection: Doctrine\Common\Collections\ArrayCollection {#9109
                -elements: []
              }
              #initialized: false
            }
            #usernameCanonical: "admin"
            #emailCanonical: "teramailtest+admin@gmail.com"
            #enabled: true
            #salt: null
            #password: "$2y$13$utOmgjkEMw8jahFnHEo51esv5N7g81X4cCPwrlLgfNnF5HljLR2jS"
            #lastLogin: DateTime @1567721304 {#6980
              date: 2019-09-05 22:08:24.0 UTC (+00:00)
            }
            #confirmationToken: "a72189fa2d8099376ca708f0eb5bb92e4e593ce8"
            #passwordRequestedAt: null
            #groups: null
          }
          -family: null
          -religion: null
          -ethnicity: null
          -grade: null
          -country: null
          -state: null
          -city: null
          -phones: null
          -mainPhone: null
          -addresses: null
          -tags: null
          -skills: null
          -organizations: null
          -groups: null
          -declinedGroupMembers: null
          -sentMessages: null
          -readMessages: null
          -archivedMessages: null
          -tips: null
          -notifications: null
          -messageReplyNotifications: null
          -notificationsDismissed: null
          -tipsDismissed: null
          -receivedMessages: null
          -receivedArchivedMessages: null
          -folderTemplatesSharedWithMe: null
          -underAge: null
          -MPAUserId: 0
          -MPAAuthenticationToken: null
          -email: null
          -hasEmail: false
          -mainPhoneNumber: null
          -messageDeliveredMetrics: null
          #publicId: null
          #createdBy: null
          #updatedBy: null
          #dateCreated: null
          +referenceProxies: []
          #createdAt: null
          #updatedAt: null
           …2
        }
      ]
    ]
    1 => array:6 [
      "file" => "/srv/api/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php"
      "line" => 713
      "function" => "prepareUpdateData"
      "class" => "Doctrine\ORM\Persisters\Entity\BasicEntityPersister"
      "type" => "->"
      "args" => array:1 [
        0 => App\Entity\User {#9103}
      ]
    ]
    2 => array:6 [
      "file" => "/srv/api/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php"
      "line" => 275
      "function" => "prepareInsertData"
      "class" => "Doctrine\ORM\Persisters\Entity\BasicEntityPersister"
      "type" => "->"
      "args" => array:1 [
        0 => App\Entity\User {#9103}
      ]
    ]
    3 => array:6 [
      "file" => "/srv/api/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php"
      "line" => 1073
      "function" => "executeInserts"
      "class" => "Doctrine\ORM\Persisters\Entity\BasicEntityPersister"
      "type" => "->"
      "args" => []
    ]
    4 => array:6 [
      "file" => "/srv/api/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php"
      "line" => 386
      "function" => "executeInserts"
      "class" => "Doctrine\ORM\UnitOfWork"
      "type" => "->"
      "args" => array:1 [
        0 => Doctrine\ORM\Mapping\ClassMetadata {#103
          +name: "App\Entity\User"
          +namespace: "App\Entity"
          +rootEntityName: "App\Entity\User"
          +customGeneratorDefinition: null
          +customRepositoryClassName: "App\Entity\Repository\UserRepository"
          +isMappedSuperclass: false
          +isEmbeddedClass: false
          +parentClasses: []
          +subClasses: []
          +embeddedClasses: []
          +namedQueries: []
          +namedNativeQueries: []
          +sqlResultSetMappings: []
          +identifier: array:1 [
            0 => "id"
          ]
...

This address to us to put a dump into this class "/srv/api/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php:677" to see what indexes were being generated, and actually we were reviewing that the index of the error wasn't part of the array of indexes array prepared to update/insert registers into the database and those indexes are generated from some Proxy/Entity classes that are generated dynamically and updated after we are executing the same command-line application.

Has somebody seen that error before? I've opened an issue because I didn't see this in other issues I've been reading, moreover, I've found another reference of the error in this page:

https://www.oipapio.com/question-537301

I've tried to solve all the warnings of relation references into my entity files but it didn't solve the problem. I hope you could help me.

How to reproduce

Trying to register several entity instances into a loop.

Expected behavior

The registers should be stored into the database after executing the flush method.

Originally created by @sinner on GitHub (Sep 15, 2019). Originally assigned to: @sinner on GitHub. ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | yes | Version | 2.6.1 #### Summary #### Current behavior Hi Symfony Community! Thank you very much in advance. I have an API that receives a CSV file to import some registers but this task is queued using Amazon SQS, so it's an asynchronous task made using the Symfony Console Component who is loading that data. This command-line application made using the Symfony Console Component uses Doctrine to store all registers read from that CSV file, so when it starts the first register is loaded perfectly into my PostgreSQL (AWS-RDS) database, but after that first register the next tries aren't loaded to the database giving the following exception "Undefined index: 000000004fc9e3630000000009549173", just after executing flush here is a bit of the track-trace of the exception: ```logs ... "exceptionMessage" => "Notice: Undefined index: 000000004fc9e3630000000009549173" "exceptionTrace" => array:19 [ 0 => array:6 [ "file" => "/srv/api/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php" "line" => 677 "function" => "getEntityIdentifier" "class" => "Doctrine\ORM\UnitOfWork" "type" => "->" "args" => array:1 [ 0 => Proxies\__CG__\App\Entity\Member {#9112 +__isInitialized__: false -id: 1 -firstName: null -lastName: null -birthDate: null -profilePictureUrl: null -occupation: null -stateText: null -stateIsoCode: null -cityText: null -postalCode: null -referenceAddress: null -deceasedAt: null -status: null -roles: null -user: App\Entity\User {#9103 #id: 2315 #publicId: "ac41571d1fcbb25901b6ad030623abccfd8390fc" #username: "admin" #displayName: "Cory Taylor" #email: "teramailtest+admin@gmail.com" -temporaryOrgAdmin: false -alreadyHasGroupAdminRole: true -alreadyHasOrgAdminRole: true -birthdaysThisWeek: true -newMessageReplies: true -groupActivityStatus: true -hasEmail: false -mainRole: "" -realMainRole: "" #displayEmail: null #createdAt: DateTime @1568315992 {#13576 date: 2019-09-12 19:19:52.971833 UTC (+00:00) } #roles: array:5 [ 0 => "ROLE_ADMIN" 1 => "ROLE_SUPER_ADMIN" 2 => "ROLE_ORGANIZATION_ADMIN" 3 => "ROLE_EVA_GROUP_ADMIN" 4 => "ROLE_EVA_MEMBER" ] #updatedAt: DateTime @1568315992 {#13576} #member: Proxies\__CG__\App\Entity\Member {#9112 …2} -languagePreference: Proxies\__CG__\App\Entity\Language {#9107 +__isInitialized__: false -id: 40 -name: null -iso: null -flag: null -enable: null #publicId: null #createdBy: null #updatedBy: null #dateCreated: null +referenceProxies: [] #createdAt: null #updatedAt: null …2 } -isVerifiedEmail: false #plainPassword: null #isIncomplete: null #mpaToken: null #mpaUserId: 166989 +referenceProxies: [] -termAndConditionAcceptances: Doctrine\ORM\PersistentCollection {#9108 -snapshot: [] -owner: App\Entity\User {#9103} -association: array:15 [ …15] -em: Doctrine\ORM\EntityManager {#224 …11} -backRefFieldName: "acceptedBy" -typeClass: Doctrine\ORM\Mapping\ClassMetadata {#8525 …} -isDirty: false #collection: Doctrine\Common\Collections\ArrayCollection {#9109 -elements: [] } #initialized: false } #usernameCanonical: "admin" #emailCanonical: "teramailtest+admin@gmail.com" #enabled: true #salt: null #password: "$2y$13$utOmgjkEMw8jahFnHEo51esv5N7g81X4cCPwrlLgfNnF5HljLR2jS" #lastLogin: DateTime @1567721304 {#6980 date: 2019-09-05 22:08:24.0 UTC (+00:00) } #confirmationToken: "a72189fa2d8099376ca708f0eb5bb92e4e593ce8" #passwordRequestedAt: null #groups: null } -family: null -religion: null -ethnicity: null -grade: null -country: null -state: null -city: null -phones: null -mainPhone: null -addresses: null -tags: null -skills: null -organizations: null -groups: null -declinedGroupMembers: null -sentMessages: null -readMessages: null -archivedMessages: null -tips: null -notifications: null -messageReplyNotifications: null -notificationsDismissed: null -tipsDismissed: null -receivedMessages: null -receivedArchivedMessages: null -folderTemplatesSharedWithMe: null -underAge: null -MPAUserId: 0 -MPAAuthenticationToken: null -email: null -hasEmail: false -mainPhoneNumber: null -messageDeliveredMetrics: null #publicId: null #createdBy: null #updatedBy: null #dateCreated: null +referenceProxies: [] #createdAt: null #updatedAt: null …2 } ] ] 1 => array:6 [ "file" => "/srv/api/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php" "line" => 713 "function" => "prepareUpdateData" "class" => "Doctrine\ORM\Persisters\Entity\BasicEntityPersister" "type" => "->" "args" => array:1 [ 0 => App\Entity\User {#9103} ] ] 2 => array:6 [ "file" => "/srv/api/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php" "line" => 275 "function" => "prepareInsertData" "class" => "Doctrine\ORM\Persisters\Entity\BasicEntityPersister" "type" => "->" "args" => array:1 [ 0 => App\Entity\User {#9103} ] ] 3 => array:6 [ "file" => "/srv/api/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php" "line" => 1073 "function" => "executeInserts" "class" => "Doctrine\ORM\Persisters\Entity\BasicEntityPersister" "type" => "->" "args" => [] ] 4 => array:6 [ "file" => "/srv/api/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php" "line" => 386 "function" => "executeInserts" "class" => "Doctrine\ORM\UnitOfWork" "type" => "->" "args" => array:1 [ 0 => Doctrine\ORM\Mapping\ClassMetadata {#103 +name: "App\Entity\User" +namespace: "App\Entity" +rootEntityName: "App\Entity\User" +customGeneratorDefinition: null +customRepositoryClassName: "App\Entity\Repository\UserRepository" +isMappedSuperclass: false +isEmbeddedClass: false +parentClasses: [] +subClasses: [] +embeddedClasses: [] +namedQueries: [] +namedNativeQueries: [] +sqlResultSetMappings: [] +identifier: array:1 [ 0 => "id" ] ... ``` This address to us to put a dump into this class "/srv/api/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php:677" to see what indexes were being generated, and actually we were reviewing that the index of the error wasn't part of the array of indexes array prepared to update/insert registers into the database and those indexes are generated from some Proxy/Entity classes that are generated dynamically and updated after we are executing the same command-line application. Has somebody seen that error before? I've opened an issue because I didn't see this in other issues I've been reading, moreover, I've found another reference of the error in this page: https://www.oipapio.com/question-537301 I've tried to solve all the warnings of relation references into my entity files but it didn't solve the problem. I hope you could help me. #### How to reproduce Trying to register several entity instances into a loop. #### Expected behavior The registers should be stored into the database after executing the flush method.
admin added the BugMissing Tests labels 2026-01-22 15:30:20 +01:00
Author
Owner

@lcobucci commented on GitHub (Sep 21, 2019):

@sinner it seems like you're manipulating objects that aren't in the UoW anymore. However, it's hard to say what happens without looking at the code. Also, have you tried to update to the latest ORM version (2.6.3)?

Would you please send us a failing test case that reproduces that behaviour via a PR? That would be very useful.

@lcobucci commented on GitHub (Sep 21, 2019): @sinner it seems like you're manipulating objects that aren't in the UoW anymore. However, it's hard to say what happens without looking at the code. Also, have you tried to update to the latest ORM version (2.6.3)? Would you please send us a failing test case that reproduces that behaviour via a PR? That would be very useful.
Author
Owner

@linibou commented on GitHub (Sep 1, 2020):

I have the same kind of issue, i'm trying to copy an entity from a database to another. I clone the entity from the source entityManager an then i persist and flush into the destination entityManager. I manage to do the same thing without error on another entity. The entity on which there is no error has just one OneToOne relation whereas entity with error has multiple OneToMany.
I'm using symfony 4.4 with php 7.3.21 with these doctrine packages:

doctrine/annotations                 1.10.3  Docblock Annotations Parser
doctrine/cache                       1.10.2  PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others.
doctrine/collections                 1.6.7   PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.
doctrine/common                      2.13.3  PHP Doctrine Common project is a library that provides additional functionality that other Doctrine projects depend on such as better reflection support, persistence interfaces, proxies, e...
doctrine/data-fixtures               1.4.3   Data Fixtures for all Doctrine Object Managers
doctrine/dbal                        2.10.2  Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.
doctrine/doctrine-bundle             1.12.10 Symfony DoctrineBundle
doctrine/doctrine-cache-bundle       1.4.0   Symfony Bundle for Doctrine Cache
doctrine/doctrine-fixtures-bundle    3.3.1   Symfony DoctrineFixturesBundle
doctrine/doctrine-migrations-bundle  v1.3.2  Symfony DoctrineMigrationsBundle
doctrine/event-manager               1.1.1   The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.
doctrine/inflector                   1.4.3   PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words.
doctrine/instantiator                1.3.1   A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                       1.2.1   PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                  v1.8.1  Database Schema migrations using Doctrine DBAL
doctrine/orm                         v2.7.3  Object-Relational-Mapper for PHP

I don't know if this will help to understand but i'm glad to talk about it since i'm stuck on it ! 😃
Any help would be apprecied 😘

Regards

@linibou commented on GitHub (Sep 1, 2020): I have the same kind of issue, i'm trying to copy an entity from a database to another. I clone the entity from the source entityManager an then i persist and flush into the destination entityManager. I manage to do the same thing without error on another entity. The entity on which there is no error has just one OneToOne relation whereas entity with error has multiple OneToMany. I'm using symfony 4.4 with php 7.3.21 with these doctrine packages: ``` doctrine/annotations 1.10.3 Docblock Annotations Parser doctrine/cache 1.10.2 PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others. doctrine/collections 1.6.7 PHP Doctrine Collections library that adds additional functionality on top of PHP arrays. doctrine/common 2.13.3 PHP Doctrine Common project is a library that provides additional functionality that other Doctrine projects depend on such as better reflection support, persistence interfaces, proxies, e... doctrine/data-fixtures 1.4.3 Data Fixtures for all Doctrine Object Managers doctrine/dbal 2.10.2 Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management. doctrine/doctrine-bundle 1.12.10 Symfony DoctrineBundle doctrine/doctrine-cache-bundle 1.4.0 Symfony Bundle for Doctrine Cache doctrine/doctrine-fixtures-bundle 3.3.1 Symfony DoctrineFixturesBundle doctrine/doctrine-migrations-bundle v1.3.2 Symfony DoctrineMigrationsBundle doctrine/event-manager 1.1.1 The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects. doctrine/inflector 1.4.3 PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words. doctrine/instantiator 1.3.1 A small, lightweight utility to instantiate objects in PHP without invoking their constructors doctrine/lexer 1.2.1 PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers. doctrine/migrations v1.8.1 Database Schema migrations using Doctrine DBAL doctrine/orm v2.7.3 Object-Relational-Mapper for PHP ``` I don't know if this will help to understand but i'm glad to talk about it since i'm stuck on it ! :smiley: Any help would be apprecied :kissing_heart: Regards
Author
Owner

@SenseException commented on GitHub (Sep 1, 2020):

@linibou Would you like to take over of what @lcobucci asked for in his previous comment?

  • Try the latest version if there's still this behaviour
  • Create a failing test
@SenseException commented on GitHub (Sep 1, 2020): @linibou Would you like to take over of what @lcobucci asked for in his previous comment? * Try the latest version if there's still this behaviour * Create a failing test
Author
Owner

@linibou commented on GitHub (Sep 3, 2020):

Hello @SenseException thank you for your answer, while i worked on a failing test i saw that i had'nt the same error on all the objects that i used for testing. I have also an error of type "A new entity was found through the relationship ...."
The thing is that i don't even know if that i want to achieve is possible :-) Maybe you can answer me ...

A1 <- B1

new A2 <- Existing B2

I have an entity A linked to B on a database 1 an i want to clone it and save it to a database 2 but i want that my A clone on database 2 is linked to an existing B object on database 2 instead of creating a new one. All my attempts dont work, even if i retrieve B object on database 2 and i link it to new A object, at flush time it seems not be managed anymore and doctrine wants to create it instead of using existing one and obviously give me an error A new entity was found through the relationship ...

$default_em = $this->container->get('doctrine')->getManager('default');
$dest_em = $this->container->get('doctrine')->getManager('db_2');

$obj_a = $default_em->getRepository(ObjectA::class)->find(1);
$obj_a_clone = clone $obj_a;

$dest_obj_b = $dest_em->getRepository(ObjectB::class)->find($obj_a->getObjectB()->getId());
if ($dest_obj_b) {
    $obj_a_clone->setObjectB($dest_obj_b);
}

$dest_em->persist($obj_a_clone);
$dest_em->flush();

Basically i want to do that but doctrine wants to insert $dest_obj_b but it already exists. Does the thing that i want to do is possible ?

@linibou commented on GitHub (Sep 3, 2020): Hello @SenseException thank you for your answer, while i worked on a failing test i saw that i had'nt the same error on all the objects that i used for testing. I have also an error of type "A new entity was found through the relationship ...." The thing is that i don't even know if that i want to achieve is possible :-) Maybe you can answer me ... ``` A1 <- B1 new A2 <- Existing B2 ``` I have an entity A linked to B on a database 1 an i want to clone it and save it to a database 2 but i want that my A clone on database 2 is linked to an existing B object on database 2 instead of creating a new one. All my attempts dont work, even if i retrieve B object on database 2 and i link it to new A object, at flush time it seems not be managed anymore and doctrine wants to create it instead of using existing one and obviously give me an error `A new entity was found through the relationship ...` ``` $default_em = $this->container->get('doctrine')->getManager('default'); $dest_em = $this->container->get('doctrine')->getManager('db_2'); $obj_a = $default_em->getRepository(ObjectA::class)->find(1); $obj_a_clone = clone $obj_a; $dest_obj_b = $dest_em->getRepository(ObjectB::class)->find($obj_a->getObjectB()->getId()); if ($dest_obj_b) { $obj_a_clone->setObjectB($dest_obj_b); } $dest_em->persist($obj_a_clone); $dest_em->flush(); ``` Basically i want to do that but doctrine wants to insert `$dest_obj_b` but it already exists. Does the thing that i want to do is possible ?
Author
Owner

@SenseException commented on GitHub (Sep 6, 2020):

  • What is the exact full error message? I don't see the culprit here.
  • Does this also happen on the newest released ORM version?
  • Maybe before you provide a failing test maybe you can create a running code example

I'm not sure if this is the same issue like initially mentioned, but I might need more information to be sure.

@SenseException commented on GitHub (Sep 6, 2020): * What is the exact full error message? I don't see the culprit here. * Does this also happen on the newest released ORM version? * Maybe before you provide a failing test maybe you can create a running code example I'm not sure if this is the same issue like initially mentioned, but I might need more information to be sure.
Author
Owner

@linibou commented on GitHub (Sep 8, 2020):

thank you for your time, i have difficulties to understand what's happening here...

  • error message: Notice: Undefined index: 000000002ee519f800000000526d95ee
  • ORM version : v2.7.3 it's seems to be the latest
  • Code producing error:
    public function copyItem($eFormation): void
    {
        $cloned_e_formation = clone $eFormation;
        $cloned_e_formation->setFormation($this->getOrCreateTargetFormation($eFormation));
        $this->getDestEm()->persist($cloned_e_formation);
        $this->getDestEm()->flush();
    }

    public function getOrCreateTargetFormation(EFormation $eFormation)
    {
        $target_formation = $this->getDestEm()->getRepository(Formation::class)->findOneBy([
            'abreviation' => $eFormation->getFormation()->getAbreviation(),
        ]);

        return $target_formation;
    }

image

i appreciate your help 🙂

@linibou commented on GitHub (Sep 8, 2020): thank you for your time, i have difficulties to understand what's happening here... * error message: `Notice: Undefined index: 000000002ee519f800000000526d95ee` * ORM version : v2.7.3 it's seems to be the latest * Code producing error: ```php public function copyItem($eFormation): void { $cloned_e_formation = clone $eFormation; $cloned_e_formation->setFormation($this->getOrCreateTargetFormation($eFormation)); $this->getDestEm()->persist($cloned_e_formation); $this->getDestEm()->flush(); } public function getOrCreateTargetFormation(EFormation $eFormation) { $target_formation = $this->getDestEm()->getRepository(Formation::class)->findOneBy([ 'abreviation' => $eFormation->getFormation()->getAbreviation(), ]); return $target_formation; } ``` ![image](https://user-images.githubusercontent.com/1038238/92465794-5f713380-f1cf-11ea-9118-c2a49d4e7543.png) i appreciate your help :slightly_smiling_face:
Author
Owner

@greg0ire commented on GitHub (Sep 8, 2020):

Relevant link: 717ef9106c/lib/Doctrine/ORM/UnitOfWork.php (L3010-L3013)

@greg0ire commented on GitHub (Sep 8, 2020): Relevant link: https://github.com/doctrine/orm/blob/717ef9106c99abf10ef6dca8091e32ea3fb77a46/lib/Doctrine/ORM/UnitOfWork.php#L3010-L3013
Author
Owner

@Fedik commented on GitHub (Sep 9, 2020):

$cloned_e_formation = clone $eFormation;

when you doing cloning, you must reset ID also, if I right remember

upd: with ID I mean identifier, depend from your mapping, something like

$metadata->setFieldValue($cloned_e_formation, 'id', null);
@Fedik commented on GitHub (Sep 9, 2020): > $cloned_e_formation = clone $eFormation; when you doing cloning, you must reset ID also, if I right remember upd: with ID I mean identifier, depend from your mapping, something like ``` $metadata->setFieldValue($cloned_e_formation, 'id', null); ```
Author
Owner

@alcalyn commented on GitHub (Jul 16, 2021):

I have this same error in a doctrine entity listener, but only for testing.

For now, I used a workaround that fixes it:

public function postPersist(User $user, LifecycleEventArgs $args): void
{
    $relatedEntity = new RelatedEntity();

    $user->setRelatedEntity($relatedEntity);

    $args->getEntityManager()->flush();

    // This only line fixes the error:
    $args->getEntityManager()->refresh($user);
}
@alcalyn commented on GitHub (Jul 16, 2021): I have this same error in a doctrine entity listener, but only for testing. For now, I used a workaround that fixes it: ``` php public function postPersist(User $user, LifecycleEventArgs $args): void { $relatedEntity = new RelatedEntity(); $user->setRelatedEntity($relatedEntity); $args->getEntityManager()->flush(); // This only line fixes the error: $args->getEntityManager()->refresh($user); } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6297