2323use Doctrine \ORM \Event \PrePersistEventArgs ;
2424use Doctrine \ORM \Event \PreRemoveEventArgs ;
2525use Doctrine \ORM \Event \PreUpdateEventArgs ;
26+ use Doctrine \ORM \Exception \EntityIdentityCollisionException ;
2627use Doctrine \ORM \Exception \ORMException ;
2728use Doctrine \ORM \Exception \UnexpectedAssociationValue ;
2829use Doctrine \ORM \Id \AssignedGenerator ;
@@ -1624,6 +1625,7 @@ public function isEntityScheduled($entity)
16241625 * the entity in question is already managed.
16251626 *
16261627 * @throws ORMInvalidArgumentException
1628+ * @throws EntityIdentityCollisionException
16271629 *
16281630 * @ignore
16291631 */
@@ -1636,34 +1638,13 @@ public function addToIdentityMap($entity)
16361638 if (isset ($ this ->identityMap [$ className ][$ idHash ])) {
16371639 if ($ this ->identityMap [$ className ][$ idHash ] !== $ entity ) {
16381640 if ($ this ->em ->getConfiguration ()->isRejectIdCollisionInIdentityMapEnabled ()) {
1639- throw new RuntimeException (
1640- sprintf (
1641- <<<'EXCEPTION'
1642- While adding an entity of class %s with an ID hash of "%s" to the identity map,
1643- another object of class %s was already present for the same ID. This exception
1644- is a safeguard against an internal inconsistency - IDs should uniquely map to
1645- entity object instances. This problem may occur if:
1646-
1647- - you use application-provided IDs and reuse ID values;
1648- - database-provided IDs are reassigned after truncating the database without
1649- clearing the EntityManager;
1650- - you might have been using EntityManager#getReference() to create a reference
1651- for a nonexistent ID that was subsequently (by the RDBMS) assigned to another
1652- entity.
1641+ throw EntityIdentityCollisionException::create ($ this ->identityMap [$ className ][$ idHash ], $ entity , $ idHash );
1642+ }
16531643
1654- Otherwise, it might be an ORM-internal inconsistency, please report it.
1655- EXCEPTION
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'
1644+ Deprecation::trigger (
1645+ 'doctrine/orm ' ,
1646+ 'https://github.com/doctrine/orm/pull/10785 ' ,
1647+ <<<'EXCEPTION'
16671648While adding an entity of class %s with an ID hash of "%s" to the identity map,
16681649another object of class %s was already present for the same ID. This will trigger
16691650an exception in ORM 3.0.
@@ -1683,12 +1664,11 @@ public function addToIdentityMap($entity)
16831664\Doctrine\ORM\Configuration::setRejectIdCollisionInIdentityMap on the entity
16841665manager's configuration.
16851666EXCEPTION
1686- ,
1687- get_class ($ entity ),
1688- $ idHash ,
1689- get_class ($ this ->identityMap [$ className ][$ idHash ])
1690- );
1691- }
1667+ ,
1668+ get_class ($ entity ),
1669+ $ idHash ,
1670+ get_class ($ this ->identityMap [$ className ][$ idHash ])
1671+ );
16921672 }
16931673
16941674 return false ;
0 commit comments