{"record":{"id":"5950dc960c4d8a0e","repo":"hibernate/hibernate-orm","slug":"embeddable-class-s-defines-an-inheritance-hiera","errorCode":null,"errorMessage":"Embeddable class '%s' defines an inheritance hierarchy and cannot be used in an '@EmbeddedId'","messagePattern":"Embeddable class '(.+?)' defines an inheritance hierarchy and cannot be used in an '@EmbeddedId'","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java","lineNumber":721,"sourceCode":"\t\t\tPropertyHolder holder,\n\t\t\tMetadataBuildingContext context) {\n\t\tassert embeddable.getDiscriminator() == null;\n\t\tfinal var columns = new AnnotatedColumns();\n\t\tcolumns.setPropertyHolder( holder );\n\t\tcolumns.setBuildingContext( context );\n\t\tdiscriminatorColumn.setParent( columns );\n\t\tfinal var discriminatorColumnBinding = new BasicValue( context, embeddable.getTable() );\n\t\tdiscriminatorColumnBinding.setAggregateColumn( embeddable.getAggregateColumn() );\n\t\tembeddable.setDiscriminator( discriminatorColumnBinding );\n\t\tdiscriminatorColumn.linkWithValue( discriminatorColumnBinding );\n\t\tdiscriminatorColumnBinding.setTypeName( discriminatorColumn.getDiscriminatorTypeName() );\n\t}\n\n\tprivate static void validateInheritanceIsSupported(\n\t\t\tPropertyHolder holder,\n\t\t\tCompositeUserType<?> compositeUserType) {\n\t\tif ( holder.isOrWithinEmbeddedId() ) {\n\t\t\tthrow new AnnotationException( String.format(\n\t\t\t\t\t\"Embeddable class '%s' defines an inheritance hierarchy and cannot be used in an '@EmbeddedId'\",\n\t\t\t\t\tholder.getClassName()\n\t\t\t) );\n\t\t}\n\t\telse if ( holder.isInIdClass() ) {\n\t\t\tthrow new AnnotationException( String.format(\n\t\t\t\t\t\"Embeddable class '%s' defines an inheritance hierarchy and cannot be used in an '@IdClass'\",\n\t\t\t\t\tholder.getClassName()\n\t\t\t) );\n\t\t}\n\t\telse if ( compositeUserType != null ) {\n\t\t\tthrow new AnnotationException( String.format(\n\t\t\t\t\t\"Embeddable class '%s' defines an inheritance hierarchy and cannot be used with a custom '@CompositeType'\",\n\t\t\t\t\tholder.getClassName()\n\t\t\t) );\n\t\t}\n\t}\n","sourceCodeStart":703,"sourceCodeEnd":739,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java#L703-L739","documentation":"Error \"Embeddable class '%s' defines an inheritance hierarchy and cannot be used in an '@EmbeddedId'\" thrown in hibernate/hibernate-orm.","triggerScenarios":"An annotation restricted to the root of an inheritance hierarchy is placed on a subclass (or the hierarchy rules are otherwise violated).","commonSituations":"SINGLE_TABLE/JOINED hierarchies where @Table, @DiscriminatorColumn, @DiscriminatorFormula, @Cache, @Immutable, @Id or @Version are declared on the wrong class of the hierarchy.","solutions":["Use an embeddable class without an inheritance hierarchy as the @EmbeddedId."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}