@@ -586,6 +586,7 @@ public function computeChangeSet(ClassMetadata $class, object $entity): void
586586 $ this ->listenersInvoker ->invoke ($ class , Events::preFlush, $ entity , new PreFlushEventArgs ($ this ->em ), $ invoke );
587587 }
588588
589+ $ isNew = ! isset ($ this ->originalEntityData [$ oid ]);
589590 $ actualData = [];
590591
591592 foreach ($ class ->propertyAccessors as $ name => $ refProp ) {
@@ -626,18 +627,26 @@ public function computeChangeSet(ClassMetadata $class, object $entity): void
626627 }
627628
628629 if (( ! $ class ->isIdentifier ($ name ) || ! $ class ->isIdGeneratorIdentity ()) && ($ name !== $ class ->versionField )) {
630+ if (! $ isNew && isset ($ class ->fieldMappings [$ name ]->notUpdatable )) {
631+ continue ;
632+ }
633+
629634 $ actualData [$ name ] = $ value ;
630635 }
631636 }
632637
633- if (! isset ( $ this -> originalEntityData [ $ oid ]) ) {
638+ if ($ isNew ) {
634639 // Entity is either NEW or MANAGED but not yet fully persisted (only has an id).
635640 // These result in an INSERT.
636641 $ this ->originalEntityData [$ oid ] = $ actualData ;
637642 $ changeSet = [];
638643
639644 foreach ($ actualData as $ propName => $ actualValue ) {
640645 if (! isset ($ class ->associationMappings [$ propName ])) {
646+ if (isset ($ class ->fieldMappings [$ propName ]->notInsertable )) {
647+ continue ;
648+ }
649+
641650 $ changeSet [$ propName ] = [null , $ actualValue ];
642651
643652 continue ;
@@ -990,6 +999,7 @@ public function recomputeSingleEntityChangeSet(ClassMetadata $class, object $ent
990999 ( ! $ class ->isIdentifier ($ name ) || ! $ class ->isIdGeneratorIdentity ())
9911000 && ($ name !== $ class ->versionField )
9921001 && ! $ class ->isCollectionValuedAssociation ($ name )
1002+ && ! isset ($ class ->fieldMappings [$ name ]->notUpdatable )
9931003 ) {
9941004 $ actualData [$ name ] = $ refProp ->getValue ($ entity );
9951005 }
0 commit comments