{"record":{"id":"9d577cdfd18e440a","repo":"hibernate/hibernate-orm","slug":"entity-class-classname-may-not-be-annotated","errorCode":null,"errorMessage":"Entity class '<className>' may not be annotated '@OnDelete'","messagePattern":"Entity class '<className>' may not be annotated '@OnDelete'","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java","lineNumber":975,"sourceCode":"\t\t\t\t\t\trootClass.setForceDiscriminator( true );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate void checkNoJoinColumns(ClassDetails annotatedClass) {\n\t\tif ( annotatedClass.hasAnnotationUsage( PrimaryKeyJoinColumns.class, modelsContext() )\n\t\t\t\t|| annotatedClass.hasAnnotationUsage( PrimaryKeyJoinColumn.class, modelsContext() ) ) {\n\t\t\tthrow new AnnotationException( \"Entity class '\" + annotatedClass.getName()\n\t\t\t\t\t+ \"' may not specify a '@PrimaryKeyJoinColumn'\" );\n\t\t}\n\t}\n\n\tprivate void checkNoOnDelete(ClassDetails annotatedClass) {\n\t\tif ( annotatedClass.hasAnnotationUsage( PrimaryKeyJoinColumns.class, modelsContext() )\n\t\t\t\t|| annotatedClass.hasAnnotationUsage( PrimaryKeyJoinColumn.class, modelsContext() ) ) {\n\t\t\tthrow new AnnotationException( \"Entity class '\" + annotatedClass.getName() + \"' may not be annotated '@OnDelete'\" );\n\t\t}\n\t}\n\n\tprivate static void handleForeignKey(ClassDetails clazzToProcess, MetadataBuildingContext context, DependantValue key) {\n\t\tfinal var foreignKey = clazzToProcess.getDirectAnnotationUsage( ForeignKey.class );\n\t\thandleForeignKeyConstraint( key, foreignKey, nestedForeignKey( clazzToProcess ), context );\n\t}\n\n\tprivate static ForeignKey nestedForeignKey(ClassDetails clazzToProcess) {\n\t\tfinal var pkJoinColumn = clazzToProcess.getDirectAnnotationUsage( PrimaryKeyJoinColumn.class );\n\t\tfinal var pkJoinColumns = clazzToProcess.getDirectAnnotationUsage( PrimaryKeyJoinColumns.class );\n\t\tif ( pkJoinColumn != null ) {\n\t\t\treturn pkJoinColumn.foreignKey();\n\t\t}\n\t\telse if ( pkJoinColumns != null ) {\n\t\t\treturn resolveContainerForeignKey( pkJoinColumns.foreignKey(), pkJoinColumns.value() );\n\t\t}\n\t\telse {","sourceCodeStart":957,"sourceCodeEnd":993,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java#L957-L993","documentation":"Error \"Entity class '<className>' may not be annotated '@OnDelete'\" thrown in hibernate/hibernate-orm.","triggerScenarios":"@OnDelete is placed on an element where cascade-delete does not apply.","commonSituations":"@OnDelete on an entity class or on a unidirectional @OneToMany without an explicit @JoinColumn.","solutions":["Remove @OnDelete from the entity class."],"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"}