{"record":{"id":"c6e7bd62e3410428","repo":"hibernate/hibernate-orm","slug":"cannot-convert-not-null-discriminator-marker-to-a","errorCode":null,"errorMessage":"Cannot convert NOT_NULL discriminator marker to a relational literal","messagePattern":"Cannot convert NOT_NULL discriminator marker to a relational literal","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/persister/entity/DiscriminatorHelper.java","lineNumber":102,"sourceCode":"\t\t\treturn DiscriminatorValue.Special.NULL;\n\t\t}\n\t\telse if ( persistentClass.isDiscriminatorValueNotNull() ) {\n\t\t\treturn DiscriminatorValue.Special.NOT_NULL;\n\t\t}\n\t\telse {\n\t\t\treturn parseDiscriminatorValue( persistentClass );\n\t\t}\n\t}\n\n\tpublic static Object toRelationalValue(DiscriminatorValue discriminatorValue) {\n\t\tif ( discriminatorValue instanceof DiscriminatorValue.Literal literal ) {\n\t\t\treturn literal.value();\n\t\t}\n\t\telse if ( discriminatorValue == DiscriminatorValue.Special.NULL ) {\n\t\t\treturn null;\n\t\t}\n\t\telse {\n\t\t\tthrow new IllegalStateException( \"Cannot convert NOT_NULL discriminator marker to a relational literal\" );\n\t\t}\n\t}\n\n\tprivate static <T> String discriminatorSqlLiteral(\n\t\t\tBasicType<T> discriminatorType,\n\t\t\tPersistentClass persistentClass,\n\t\t\tDialect dialect) {\n\t\treturn jdbcLiteral(\n\t\t\t\tdiscriminatorType.getJavaTypeDescriptor().fromString( persistentClass.getDiscriminatorValue() ),\n\t\t\t\tdiscriminatorType.getJdbcLiteralFormatter(),\n\t\t\t\tdialect\n\t\t);\n\t}\n\n\tpublic static <T> String jdbcLiteral(T value, JdbcLiteralFormatter<T> formatter, Dialect dialect) {\n\t\ttry {\n\t\t\treturn formatter.toJdbcLiteral( value, dialect, null );\n\t\t}","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/persister/entity/DiscriminatorHelper.java#L84-L120","documentation":"DiscriminatorHelper.toRelationalValue converts a resolved DiscriminatorValue into a JDBC value: a Literal yields its value and the special NULL marker yields null, but the NOT_NULL marker (from the legacy @DiscriminatorValue(\"not null\") mapping) has no single literal, so converting it throws IllegalStateException. Code paths that need a concrete bindable discriminator value (restrictions, insert parameter binding) fail for entities mapped with the marker.","triggerScenarios":"An entity mapped with @DiscriminatorValue(\"not null\") — meaning 'rows with a non-null discriminator belong to this class' — followed by a call to toRelationalValue(...) or any runtime path that binds that entity's discriminator as a literal/parameter.","commonSituations":"Legacy Hibernate mappings carried forward from very old versions where 'null'/'not null' special discriminator markers were common; migrating such hierarchies onto code paths (inserts, criteria, filters) that need real literals.","solutions":["Give the entity a real discriminator value instead of the 'not null' marker","Where the marker semantics are required, express it as a predicate (discriminator is not null) instead of converting it to a literal","Verify no framework or generated code binds discriminator literals for marker-mapped entities"],"exampleFix":"// before\n@DiscriminatorValue(\"not null\")\npublic class Miscellaneous extends Payment { }\n\n// after\n@DiscriminatorValue(\"MISC\")\npublic class Miscellaneous extends Payment { }","handlingStrategy":"validation","validationCode":"DiscriminatorValue val = entity.getAnnotation(DiscriminatorValue.class);\nif ( val != null && (\"not null\".equalsIgnoreCase(val.value())\n                   || \"null\".equalsIgnoreCase(val.value())) ) {\n    // marker value: never feed this entity's discriminator into literal conversion / insert binding\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Replace legacy 'null'/'not null' discriminator markers with real values during upgrades","Treat the markers as predicates (IS NULL / IS NOT NULL) in custom SQL, not as literals","Grep old hbm.xml files for discriminator-value=\"not null\" before migrating"],"tags":["hibernate","orm","discriminator","inheritance","legacy-mapping"],"backgroundTag":"discriminator-null-not-null-marker","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}