{"record":{"id":"133c5c85102f8e79","repo":"hibernate/hibernate-orm","slug":"illegal-discriminator-type-discriminatortype","errorCode":null,"errorMessage":"Illegal discriminator type: {discriminatorType}","messagePattern":"Illegal discriminator type: (.+?)","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/persister/entity/DiscriminatorHelper.java","lineNumber":42,"sourceCode":"/**\n * Operations needed by persisters for working with discriminators.\n *\n * @author Gavin King\n */\n@Internal\npublic class DiscriminatorHelper {\n\n\t/**\n\t * The underlying BasicType as the \"JDBC mapping\" between the relational {@link org.hibernate.type.descriptor.java.JavaType}\n\t * and the {@link org.hibernate.type.descriptor.jdbc.JdbcType}.\n\t */\n\tstatic BasicType<?> getDiscriminatorType(PersistentClass persistentClass) {\n\t\tfinal Type discriminatorType = persistentClass.getDiscriminator().getType();\n\t\tif ( discriminatorType instanceof BasicType<?> basicType ) {\n\t\t\treturn basicType;\n\t\t}\n\t\telse {\n\t\t\tthrow new MappingException( \"Illegal discriminator type: \" + discriminatorType.getName() );\n\t\t}\n\t}\n\n\tpublic static BasicType<?> getDiscriminatorType(Component component) {\n\t\tfinal Type discriminatorType = component.getDiscriminator().getType();\n\t\tif ( discriminatorType instanceof BasicType<?> basicType ) {\n\t\t\treturn basicType;\n\t\t}\n\t\telse {\n\t\t\tthrow new MappingException( \"Illegal discriminator type: \" + discriminatorType.getName() );\n\t\t}\n\t}\n\n\tpublic static String getDiscriminatorSQLValue(PersistentClass persistentClass, Dialect dialect) {\n\t\tif ( persistentClass.isDiscriminatorValueNull() ) {\n\t\t\treturn InFragment.NULL;\n\t\t}\n\t\telse if ( persistentClass.isDiscriminatorValueNotNull() ) {","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/persister/entity/DiscriminatorHelper.java#L24-L60","documentation":"DiscriminatorHelper.getDiscriminatorType(PersistentClass) extracts the entity discriminator's JDBC mapping and requires its Type to be a BasicType. A discriminator is a single-column value, so if the mapped Type is anything else (a component/composite type or a custom Type that does not resolve to BasicType) boot fails with MappingException('Illegal discriminator type'). Thrown while persisters are built at SessionFactory startup.","triggerScenarios":"Mapping the entity discriminator with a non-basic type: a custom UserType/@Type on the discriminator column that is not a BasicType, a discriminator selectable backed by a composite type, or hand-built PersistentClass metadata whose getDiscriminator().getType() is not basic.","commonSituations":"Custom type registered for the discriminator column; exotic mappings where the discriminator is derived from a composite expression; custom metadata sources constructing PersistentClass programmatically.","solutions":["Map the discriminator with a standard basic type (String, Integer, char) via @DiscriminatorColumn","Remove any custom @Type/UserType applied to the discriminator column","If building boot metadata programmatically, ensure getDiscriminator().getType() resolves to a registered BasicType"],"exampleFix":"// before\n@Entity\n@DiscriminatorColumn(name = \"kind\", discriminatorType = STRING) // but a custom @Type is applied via XML/programmatic mapping\n\n// after\n@Entity\n@DiscriminatorColumn(name = \"kind\", discriminatorType = STRING) // basic type only, no custom type override","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    SessionFactory sf = metadata.getSessionFactoryBuilder().build();\n}\ncatch ( org.hibernate.MappingException e ) {\n    // discriminator type is not a BasicType: fail deployment with e.getMessage()\n    throw new IllegalStateException(\"SessionFactory boot failed: \" + e.getMessage(), e);\n}","preventionTips":["Map discriminator columns with @DiscriminatorColumn and standard types only","Never apply custom/composite types to discriminator columns","Boot the SessionFactory in a CI smoke test so discriminator mapping errors are caught before release"],"tags":["hibernate","orm","discriminator","mapping","inheritance"],"backgroundTag":"illegal-discriminator-type","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}