-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This adds a dedicated exception for the case that objects with colliding identities are to be put into the identity map. Implements #10872.
- Loading branch information
Showing
4 changed files
with
59 additions
and
37 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
lib/Doctrine/ORM/Exception/EntityIdentityCollisionException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ORM\Exception; | ||
|
||
use function get_class; | ||
use function sprintf; | ||
|
||
final class EntityIdentityCollisionException extends ORMException | ||
{ | ||
/** | ||
* @param object $existingEntity | ||
* @param object $newEntity | ||
*/ | ||
public static function create($existingEntity, $newEntity, string $idHash): self | ||
{ | ||
return new self( | ||
sprintf( | ||
<<<'EXCEPTION' | ||
While adding an entity of class %s with an ID hash of "%s" to the identity map, | ||
another object of class %s was already present for the same ID. This exception | ||
is a safeguard against an internal inconsistency - IDs should uniquely map to | ||
entity object instances. This problem may occur if: | ||
- you use application-provided IDs and reuse ID values; | ||
- database-provided IDs are reassigned after truncating the database without | ||
clearing the EntityManager; | ||
- you might have been using EntityManager#getReference() to create a reference | ||
for a nonexistent ID that was subsequently (by the RDBMS) assigned to another | ||
entity. | ||
Otherwise, it might be an ORM-internal inconsistency, please report it. | ||
EXCEPTION | ||
, | ||
get_class($newEntity), | ||
$idHash, | ||
get_class($existingEntity) | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters