{"record":{"id":"00a35ae0c7c15f78","repo":"hibernate/hibernate-orm","slug":"class-componentclassname-is-an-embeddable-t-00a35a","errorCode":null,"errorMessage":"Class '<componentClassName>' is an '@Embeddable' type and may not be annotated '@DiscriminatorOptions'","messagePattern":"Class '<componentClassName>' is an '@Embeddable' type and may not be annotated '@DiscriminatorOptions'","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/binder/internal/DiscriminatorOptionsBinder.java","lineNumber":41,"sourceCode":"\t@Override\n\tpublic void bind(DiscriminatorOptions options, MetadataBuildingContext context, PersistentClass persistentClass) {\n\t\tif ( persistentClass instanceof RootClass rootClass ) {\n\t\t\tif ( !rootClass.hasDiscriminator() ) {\n\t\t\t\tthrow new AnnotationException( \"Root entity '\" + rootClass.getEntityName()\n\t\t\t\t\t\t+ \"' is annotated '@DiscriminatorOptions' but has no discriminator column\" );\n\t\t\t}\n\t\t\trootClass.setForceDiscriminator( options.force() );\n\t\t\trootClass.setDiscriminatorInsertable( options.insert() );\n\t\t}\n\t\telse {\n\t\t\tthrow new AnnotationException(\"Class '\" + persistentClass.getClassName()\n\t\t\t\t\t+ \"' is not the root class of an entity inheritance hierarchy and may not be annotated '@DiscriminatorOptions'\");\n\t\t}\n\t}\n\n\t@Override\n\tpublic void bind(DiscriminatorOptions options, MetadataBuildingContext context, Component embeddableClass) {\n\t\tthrow new AnnotationException(\"Class '\" + embeddableClass.getComponentClassName()\n\t\t\t\t+ \"' is an '@Embeddable' type and may not be annotated '@DiscriminatorOptions'\");\n\t}\n}\n","sourceCodeStart":23,"sourceCodeEnd":45,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/binder/internal/DiscriminatorOptionsBinder.java#L23-L45","documentation":"The Component overload of DiscriminatorOptionsBinder.bind always throws: @DiscriminatorOptions on an @Embeddable class is rejected because embeddables take no part in entity inheritance hierarchies and have no discriminator column to configure.","triggerScenarios":"An @Embeddable class annotated @DiscriminatorOptions is registered in the metadata; SessionFactory bootstrap binds the Component mapping and throws unconditionally.","commonSituations":"Annotation sweeps or IDE templates applying inheritance options to all classes; embeddables that used to be entities; misunderstanding @DiscriminatorOptions as related to embeddable polymorphism.","solutions":["Remove @DiscriminatorOptions from the @Embeddable class.","If the class needs inheritance with a discriminator, map it as an entity hierarchy — @DiscriminatorOptions never applies to embeddables."],"exampleFix":"// before\n@Embeddable\n@DiscriminatorOptions(force = true)\npublic class Address { ... }\n\n// after\n@Embeddable\npublic class Address { ... }","handlingStrategy":"validation","validationCode":"for (Class<?> cls : persistentClasses) {\n    if (cls.isAnnotationPresent(jakarta.persistence.Embeddable.class)\n            && cls.isAnnotationPresent(org.hibernate.annotations.DiscriminatorOptions.class)) {\n        throw new IllegalStateException(\"@DiscriminatorOptions not allowed on @Embeddable \" + cls.getName());\n    }\n}","typeGuard":null,"tryCatchPattern":"Catch org.hibernate.AnnotationException during SessionFactory build; abort with the class name from the message.","preventionTips":["Keep entity-inheritance annotations away from embeddables.","Validate annotation sets per class kind (@Entity vs @Embeddable) in CI."],"tags":["hibernate","jpa","annotations","embeddable","discriminator","orm-mapping"],"backgroundTag":"jpa-annotation-misplacement","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}