{"id":"883f281ff6ce7bbe","repo":"typeorm/typeorm","slug":"entities-entitymetadata-name-and-samediscrimi","errorCode":null,"errorMessage":"Entities ${entityMetadata.name} and ${sameDiscriminatorValueEntityMetadata.name} have the same discriminator values. Make sure they are different while using the @ChildEntity decorator.","messagePattern":"Entities (.+?) and (.+?) have the same discriminator values\\. Make sure they are different while using the @ChildEntity decorator\\.","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"src/metadata-builder/EntityMetadataValidator.ts","lineNumber":117,"sourceCode":"            const sameDiscriminatorValueEntityMetadata =\n                allEntityMetadatas.find((metadata) => {\n                    return (\n                        metadata !== entityMetadata &&\n                        (metadata.inheritancePattern === \"STI\" ||\n                            metadata.tableType === \"entity-child\") &&\n                        metadata.tableName === entityMetadata.tableName &&\n                        metadata.discriminatorValue ===\n                            entityMetadata.discriminatorValue &&\n                        metadata.inheritanceTree.some(\n                            (parent) =>\n                                entityMetadata.inheritanceTree.indexOf(\n                                    parent,\n                                ) !== -1,\n                        )\n                    )\n                })\n            if (sameDiscriminatorValueEntityMetadata)\n                throw new TypeORMError(\n                    `Entities ${entityMetadata.name} and ${sameDiscriminatorValueEntityMetadata.name} have the same discriminator values. Make sure they are different while using the @ChildEntity decorator.`,\n                )\n        }\n\n        if (!(driver.options.type === \"mongodb\")) {\n            entityMetadata.columns\n                .filter((column) => !column.isVirtualProperty)\n                .forEach((column) => {\n                    const normalizedColumn = driver.normalizeType(\n                        column,\n                    ) as ColumnType\n                    if (!driver.supportedDataTypes.includes(normalizedColumn))\n                        throw new DataTypeNotSupportedError(\n                            column,\n                            normalizedColumn,\n                            driver.options.type,\n                        )\n                    if (","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/typeorm/typeorm/blob/04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96/src/metadata-builder/EntityMetadataValidator.ts#L99-L135","documentation":"Two child entities that share the same base table and the same discriminator value would be indistinguishable in queries, so validation throws. The check compares `tableName` and `discriminatorValue` across entities sharing an inheritance tree.","triggerScenarios":"`@ChildEntity('user')` on two classes that inherit from the same base entity.","commonSituations":"Copy-pasting a child entity and forgetting to change its discriminator value; merging entity hierarchies.","solutions":["Give each child entity a unique discriminator value","If two classes should collapse to one type, merge them into a single child entity"],"exampleFix":"// before\n@ChildEntity('user') class Admin extends User {}\n@ChildEntity('user') class Guest extends User {}\n// after\n@ChildEntity('admin') class Admin extends User {}\n@ChildEntity('guest') class Guest extends User {}","handlingStrategy":"validation","validationCode":"function assertUniqueDiscriminatorValues(metadatas: EntityMetadata[]) {\n  const seen = new Map<string, string>()\n  for (const m of metadatas) {\n    if (m.inheritancePattern !== 'STI' && m.tableType !== 'entity-child') continue\n    const key = `${m.tableName}::${m.discriminatorValue}`\n    if (seen.has(key)) throw new Error(`duplicate discriminator value ${m.discriminatorValue} on table ${m.tableName}`)\n    seen.set(key, m.name)\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat discriminator values as an enum shared across the inheritance hierarchy","Add a test asserting uniqueness of discriminator values per table"],"tags":["sti","inheritance","discriminator","validation"],"analyzedSha":"04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96","analyzedAt":"2026-08-03T18:27:32.281Z","schemaVersion":2}