@@ -692,6 +692,7 @@ public function computeChangeSet(ClassMetadata $class, $entity)
692692 if ($ class ->isCollectionValuedAssociation ($ name ) && $ value !== null ) {
693693 if ($ value instanceof PersistentCollection) {
694694 if ($ value ->getOwner () === $ entity ) {
695+ $ actualData [$ name ] = $ value ;
695696 continue ;
696697 }
697698
@@ -1634,8 +1635,10 @@ public function addToIdentityMap($entity)
16341635
16351636 if (isset ($ this ->identityMap [$ className ][$ idHash ])) {
16361637 if ($ this ->identityMap [$ className ][$ idHash ] !== $ entity ) {
1637- throw new RuntimeException (sprintf (
1638- <<<'EXCEPTION'
1638+ if ($ this ->em ->getConfiguration ()->isRejectIdCollisionInIdentityMapEnabled ()) {
1639+ throw new RuntimeException (
1640+ sprintf (
1641+ <<<'EXCEPTION'
16391642While adding an entity of class %s with an ID hash of "%s" to the identity map,
16401643another object of class %s was already present for the same ID. This exception
16411644is a safeguard against an internal inconsistency - IDs should uniquely map to
@@ -1650,11 +1653,42 @@ public function addToIdentityMap($entity)
16501653
16511654Otherwise, it might be an ORM-internal inconsistency, please report it.
16521655EXCEPTION
1653- ,
1654- get_class ($ entity ),
1655- $ idHash ,
1656- get_class ($ this ->identityMap [$ className ][$ idHash ])
1657- ));
1656+ ,
1657+ get_class ($ entity ),
1658+ $ idHash ,
1659+ get_class ($ this ->identityMap [$ className ][$ idHash ])
1660+ )
1661+ );
1662+ } else {
1663+ Deprecation::trigger (
1664+ 'doctrine/orm ' ,
1665+ 'https://github.com/doctrine/orm/pull/10785 ' ,
1666+ <<<'EXCEPTION'
1667+ While adding an entity of class %s with an ID hash of "%s" to the identity map,
1668+ another object of class %s was already present for the same ID. This will trigger
1669+ an exception in ORM 3.0.
1670+
1671+ IDs should uniquely map to entity object instances. This problem may occur if:
1672+
1673+ - you use application-provided IDs and reuse ID values;
1674+ - database-provided IDs are reassigned after truncating the database without
1675+ clearing the EntityManager;
1676+ - you might have been using EntityManager#getReference() to create a reference
1677+ for a nonexistent ID that was subsequently (by the RDBMS) assigned to another
1678+ entity.
1679+
1680+ Otherwise, it might be an ORM-internal inconsistency, please report it.
1681+
1682+ To opt-in to the new exception, call
1683+ \Doctrine\ORM\Configuration::setRejectIdCollisionInIdentityMap on the entity
1684+ manager's configuration.
1685+ EXCEPTION
1686+ ,
1687+ get_class ($ entity ),
1688+ $ idHash ,
1689+ get_class ($ this ->identityMap [$ className ][$ idHash ])
1690+ );
1691+ }
16581692 }
16591693
16601694 return false ;
0 commit comments