hibernate/hibernate-orm · error · AnnotationException
Entity class '<className>' may not be annotated '@OnDelete'
Error message
Entity class '<className>' may not be annotated '@OnDelete'
What it means
Error "Entity class '<className>' may not be annotated '@OnDelete'" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java:975
rootClass.setForceDiscriminator( true );
}
}
}
}
}
private void checkNoJoinColumns(ClassDetails annotatedClass) {
if ( annotatedClass.hasAnnotationUsage( PrimaryKeyJoinColumns.class, modelsContext() )
|| annotatedClass.hasAnnotationUsage( PrimaryKeyJoinColumn.class, modelsContext() ) ) {
throw new AnnotationException( "Entity class '" + annotatedClass.getName()
+ "' may not specify a '@PrimaryKeyJoinColumn'" );
}
}
private void checkNoOnDelete(ClassDetails annotatedClass) {
if ( annotatedClass.hasAnnotationUsage( PrimaryKeyJoinColumns.class, modelsContext() )
|| annotatedClass.hasAnnotationUsage( PrimaryKeyJoinColumn.class, modelsContext() ) ) {
throw new AnnotationException( "Entity class '" + annotatedClass.getName() + "' may not be annotated '@OnDelete'" );
}
}
private static void handleForeignKey(ClassDetails clazzToProcess, MetadataBuildingContext context, DependantValue key) {
final var foreignKey = clazzToProcess.getDirectAnnotationUsage( ForeignKey.class );
handleForeignKeyConstraint( key, foreignKey, nestedForeignKey( clazzToProcess ), context );
}
private static ForeignKey nestedForeignKey(ClassDetails clazzToProcess) {
final var pkJoinColumn = clazzToProcess.getDirectAnnotationUsage( PrimaryKeyJoinColumn.class );
final var pkJoinColumns = clazzToProcess.getDirectAnnotationUsage( PrimaryKeyJoinColumns.class );
if ( pkJoinColumn != null ) {
return pkJoinColumn.foreignKey();
}
else if ( pkJoinColumns != null ) {
return resolveContainerForeignKey( pkJoinColumns.foreignKey(), pkJoinColumns.value() );
}
else {View on GitHub (pinned to fad1729dce)
Solutions
- Remove @OnDelete from the entity class.
When it happens
Trigger: @OnDelete is placed on an element where cascade-delete does not apply.
Common situations: @OnDelete on an entity class or on a unidirectional @OneToMany without an explicit @JoinColumn.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/9d577cdfd18e440a.
Report an issue: GitHub.