3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the MIT license. For more information, see
17 * <http://www.phpdoctrine.org>.
20 namespace Doctrine\ORM\Mapping;
23 * A MappingException indicates that something is wrong with the mapping setup.
27 class MappingException extends \Doctrine\ORM\ORMException
29 public static function pathRequired()
31 return new self("Specifying the paths to your entities is required ".
32 "in the AnnotationDriver to retrieve all class names.");
35 public static function identifierRequired($entityName)
37 if (null !== ($parent = get_parent_class($entityName))) {
38 return new self(sprintf(
39 'No identifier/primary key specified for Entity "%s" sub class of "%s". Every Entity must have an identifier/primary key.',
44 return new self(sprintf(
45 'No identifier/primary key specified for Entity "%s". Every Entity must have an identifier/primary key.',
51 public static function invalidInheritanceType($entityName, $type)
53 return new self("The inheritance type '$type' specified for '$entityName' does not exist.");
56 public static function generatorNotAllowedWithCompositeId()
58 return new self("Id generators can't be used with a composite id.");
61 public static function missingFieldName($entity)
63 return new self("The field or association mapping misses the 'fieldName' attribute in entity '$entity'.");
66 public static function missingTargetEntity($fieldName)
68 return new self("The association mapping '$fieldName' misses the 'targetEntity' attribute.");
71 public static function missingSourceEntity($fieldName)
73 return new self("The association mapping '$fieldName' misses the 'sourceEntity' attribute.");
76 public static function mappingFileNotFound($entityName, $fileName)
78 return new self("No mapping file found named '$fileName' for class '$entityName'.");
82 * Exception for invalid property name override.
84 * @param string $className The entity's name
85 * @param string $fieldName
87 public static function invalidOverrideFieldName($className, $fieldName)
89 return new self("Invalid field override named '$fieldName' for class '$className'.");
93 * Exception for invalid property type override.
95 * @param string $className The entity's name
96 * @param string $fieldName
98 public static function invalidOverrideFieldType($className, $fieldName)
100 return new self("The column type of attribute '$fieldName' on class '$className' could not be changed.");
103 public static function mappingNotFound($className, $fieldName)
105 return new self("No mapping found for field '$fieldName' on class '$className'.");
108 public static function queryNotFound($className, $queryName)
110 return new self("No query found named '$queryName' on class '$className'.");
113 public static function resultMappingNotFound($className, $resultName)
115 return new self("No result set mapping found named '$resultName' on class '$className'.");
118 public static function emptyQueryMapping($entity, $queryName)
120 return new self('Query named "'.$queryName.'" in "'.$entity.'" could not be empty.');
123 public static function nameIsMandatoryForQueryMapping($className)
125 return new self("Query name on entity class '$className' is not defined.");
128 public static function missingQueryMapping($entity, $queryName)
130 return new self('Query named "'.$queryName.'" in "'.$entity.' requires a result class or result set mapping.');
133 public static function missingResultSetMappingEntity($entity, $resultName)
135 return new self('Result set mapping named "'.$resultName.'" in "'.$entity.' requires a entity class name.');
138 public static function missingResultSetMappingFieldName($entity, $resultName)
140 return new self('Result set mapping named "'.$resultName.'" in "'.$entity.' requires a field name.');
143 public static function nameIsMandatoryForSqlResultSetMapping($className)
145 return new self("Result set mapping name on entity class '$className' is not defined.");
148 public static function oneToManyRequiresMappedBy($fieldName)
150 return new self("OneToMany mapping on field '$fieldName' requires the 'mappedBy' attribute.");
153 public static function joinTableRequired($fieldName)
155 return new self("The mapping of field '$fieldName' requires an the 'joinTable' attribute.");
159 * Called if a required option was not found but is required
161 * @param string $field which field cannot be processed?
162 * @param string $expectedOption which option is required
163 * @param string $hint Can optionally be used to supply a tip for common mistakes,
164 * e.g. "Did you think of the plural s?"
165 * @return MappingException
167 static function missingRequiredOption($field, $expectedOption, $hint = '')
169 $message = "The mapping of field '{$field}' is invalid: The option '{$expectedOption}' is required.";
171 if ( ! empty($hint)) {
172 $message .= ' (Hint: ' . $hint . ')';
175 return new self($message);
179 * Generic exception for invalid mappings.
181 * @param string $fieldName
183 public static function invalidMapping($fieldName)
185 return new self("The mapping of field '$fieldName' is invalid.");
189 * Exception for reflection exceptions - adds the entity name,
190 * because there might be long classnames that will be shortened
191 * within the stacktrace
193 * @param string $entity The entity's name
194 * @param \ReflectionException $previousException
196 public static function reflectionFailure($entity, \ReflectionException $previousException)
198 return new self('An error occurred in ' . $entity, 0, $previousException);
201 public static function joinColumnMustPointToMappedField($className, $joinColumn)
203 return new self('The column ' . $joinColumn . ' must be mapped to a field in class '
204 . $className . ' since it is referenced by a join column of another class.');
207 public static function classIsNotAValidEntityOrMappedSuperClass($className)
209 if (null !== ($parent = get_parent_class($className))) {
210 return new self(sprintf(
211 'Class "%s" sub class of "%s" is not a valid entity or mapped super class.',
216 return new self(sprintf(
217 'Class "%s" is not a valid entity or mapped super class.',
222 public static function propertyTypeIsRequired($className, $propertyName)
224 return new self("The attribute 'type' is required for the column description of property ".$className."::\$".$propertyName.".");
227 public static function tableIdGeneratorNotImplemented($className)
229 return new self("TableIdGenerator is not yet implemented for use with class ".$className);
233 * @param string $entity The entity's name
234 * @param string $fieldName The name of the field that was already declared
236 public static function duplicateFieldMapping($entity, $fieldName)
238 return new self('Property "'.$fieldName.'" in "'.$entity.'" was already declared, but it must be declared only once');
241 public static function duplicateAssociationMapping($entity, $fieldName)
243 return new self('Property "'.$fieldName.'" in "'.$entity.'" was already declared, but it must be declared only once');
246 public static function duplicateQueryMapping($entity, $queryName)
248 return new self('Query named "'.$queryName.'" in "'.$entity.'" was already declared, but it must be declared only once');
251 public static function duplicateResultSetMapping($entity, $resultName)
253 return new self('Result set mapping named "'.$resultName.'" in "'.$entity.'" was already declared, but it must be declared only once');
256 public static function singleIdNotAllowedOnCompositePrimaryKey($entity)
258 return new self('Single id is not allowed on composite primary key in entity '.$entity);
261 public static function unsupportedOptimisticLockingType($entity, $fieldName, $unsupportedType)
263 return new self('Locking type "'.$unsupportedType.'" (specified in "'.$entity.'", field "'.$fieldName.'") '
264 .'is not supported by Doctrine.'
268 public static function fileMappingDriversRequireConfiguredDirectoryPath($path = null)
270 if ( ! empty($path)) {
271 $path = '[' . $path . ']';
275 'File mapping drivers must have a valid directory path, ' .
276 'however the given path ' . $path . ' seems to be incorrect!'
281 * Throws an exception that indicates that a class used in a discriminator map does not exist.
282 * An example would be an outdated (maybe renamed) classname.
284 * @param string $className The class that could not be found
285 * @param string $owningClass The class that declares the discriminator map.
288 public static function invalidClassInDiscriminatorMap($className, $owningClass)
291 "Entity class '$className' used in the discriminator map of class '$owningClass' ".
296 public static function duplicateDiscriminatorEntry($className, array $entries, array $map)
299 "The entries " . implode(', ', $entries) . " in discriminator map of class '" . $className . "' is duplicated. " .
300 "If the discriminator map is automatically generated you have to convert it to an explicit discriminator map now. " .
301 "The entries of the current map are: @DiscriminatorMap({" . implode(', ', array_map(
302 function($a, $b) { return "'$a': '$b'"; }, array_keys($map), array_values($map)
307 public static function missingDiscriminatorMap($className)
309 return new self("Entity class '$className' is using inheritance but no discriminator map was defined.");
312 public static function missingDiscriminatorColumn($className)
314 return new self("Entity class '$className' is using inheritance but no discriminator column was defined.");
317 public static function invalidDiscriminatorColumnType($className, $type)
319 return new self("Discriminator column type on entity class '$className' is not allowed to be '$type'. 'string' or 'integer' type variables are suggested!");
322 public static function nameIsMandatoryForDiscriminatorColumns($className)
324 return new self("Discriminator column name on entity class '$className' is not defined.");
327 public static function cannotVersionIdField($className, $fieldName)
329 return new self("Setting Id field '$fieldName' as versionale in entity class '$className' is not supported.");
332 public static function sqlConversionNotAllowedForIdentifiers($className, $fieldName, $type)
334 return new self("It is not possible to set id field '$fieldName' to type '$type' in entity class '$className'. The type '$type' requires conversion SQL which is not allowed for identifiers.");
338 * @param string $className
339 * @param string $columnName
342 public static function duplicateColumnName($className, $columnName)
344 return new self("Duplicate definition of column '".$columnName."' on entity '".$className."' in a field or discriminator column mapping.");
347 public static function illegalToManyAssocationOnMappedSuperclass($className, $field)
349 return new self("It is illegal to put an inverse side one-to-many or many-to-many association on mapped superclass '".$className."#".$field."'.");
353 * @param string $className
354 * @param string $targetEntity
355 * @param string $targetField
358 public static function cannotMapCompositePrimaryKeyEntitiesAsForeignId($className, $targetEntity, $targetField)
360 return new self("It is not possible to map entity '".$className."' with a composite primary key ".
361 "as part of the primary key of another entity '".$targetEntity."#".$targetField."'.");
364 public static function noSingleAssociationJoinColumnFound($className, $field)
366 return new self("'$className#$field' is not an association with a single join column.");
369 public static function noFieldNameFoundForColumn($className, $column)
371 return new self("Cannot find a field on '$className' that is mapped to column '$column'. Either the ".
372 "field does not exist or an association exists but it has multiple join columns.");
375 public static function illegalOrphanRemovalOnIdentifierAssociation($className, $field)
377 return new self("The orphan removal option is not allowed on an association that is ".
378 "part of the identifier in '$className#$field'.");
381 public static function illegalOrphanRemoval($className, $field)
383 return new self("Orphan removal is only allowed on one-to-one and one-to-many ".
384 "associations, but " . $className."#" .$field . " is not.");
387 public static function illegalInverseIdentifierAssocation($className, $field)
389 return new self("An inverse association is not allowed to be identifier in '$className#$field'.");
392 public static function illegalToManyIdentifierAssoaction($className, $field)
394 return new self("Many-to-many or one-to-many associations are not allowed to be identifier in '$className#$field'.");
397 public static function noInheritanceOnMappedSuperClass($className)
399 return new self("Its not supported to define inheritance information on a mapped superclass '" . $className . "'.");
402 public static function mappedClassNotPartOfDiscriminatorMap($className, $rootClassName)
405 "Entity '" . $className . "' has to be part of the discriminator map of '" . $rootClassName . "' " .
406 "to be properly mapped in the inheritance hierachy. Alternatively you can make '".$className."' an abstract class " .
407 "to avoid this exception from occuring."
411 public static function lifecycleCallbackMethodNotFound($className, $methodName)
413 return new self("Entity '" . $className . "' has no method '" . $methodName . "' to be registered as lifecycle callback.");
416 public static function invalidFetchMode($className, $annotation)
418 return new self("Entity '" . $className . "' has a mapping with invalid fetch mode '" . $annotation . "'");
421 public static function compositeKeyAssignedIdGeneratorRequired($className)
423 return new self("Entity '". $className . "' has a composite identifier but uses an ID generator other than manually assigning (Identity, Sequence). This is not supported.");
426 public static function invalidTargetEntityClass($targetEntity, $sourceEntity, $associationName)
428 return new self("The target-entity " . $targetEntity . " cannot be found in '" . $sourceEntity."#".$associationName."'.");
431 public static function invalidCascadeOption(array $cascades, $className, $propertyName)
433 $cascades = implode(", ", array_map(function ($e) { return "'" . $e . "'"; }, $cascades));
434 return new self(sprintf(
435 "You have specified invalid cascade options for %s::$%s: %s; available options: 'remove', 'persist', 'refresh', 'merge', and 'detach'",