From 9cd8f85a8cef8d97c3d9dfe03d45b580998e0032 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 18 Dec 2011 00:32:35 +0100 Subject: [PATCH] DDC-1456 - Disallow setting id generators on composite identifiers. --- lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php | 4 ++++ lib/Doctrine/ORM/Mapping/MappingException.php | 5 +++++ tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php | 4 +--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 82ff14531..8801344ff 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -371,6 +371,10 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface // second condition is necessary for mapped superclasses in the middle of an inheritance hierachy throw MappingException::noInheritanceOnMappedSuperClass($class->name); } + + if ($class->usesIdGenerator() && $class->isIdentifierComposite) { + throw MappingException::compositeKeyAssignedIdGeneratorRequired($class->name); + } } /** diff --git a/lib/Doctrine/ORM/Mapping/MappingException.php b/lib/Doctrine/ORM/Mapping/MappingException.php index 014714bf8..82b6f138b 100644 --- a/lib/Doctrine/ORM/Mapping/MappingException.php +++ b/lib/Doctrine/ORM/Mapping/MappingException.php @@ -314,4 +314,9 @@ class MappingException extends \Doctrine\ORM\ORMException { return new self("Entity '" . $className . "' has a mapping with invalid fetch mode '" . $annotation . "'"); } + + public static function compositeKeyAssignedIdGeneratorRequired($className) + { + return new self("Entity '". $className . "' has a composite identifier but uses an ID generator other than manually assigning (Identity, Sequence). This is not supported."); + } } diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php index 0fc3bb636..1d68a9bcb 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php @@ -141,13 +141,11 @@ class InvalidEntity2 { /** * @Id @Column - * @GeneratedValue(strategy="AUTO") */ protected $key3; /** * @Id @Column - * @GeneratedValue(strategy="AUTO") */ protected $key4; @@ -155,4 +153,4 @@ class InvalidEntity2 * @ManyToOne(targetEntity="InvalidEntity1") */ protected $assoc; -} \ No newline at end of file +}