hibernate/hibernate-orm · error · AnnotationException

Entity class '${className}' specifies an '@SQLRestriction' b

Error message

Entity class '${className}' specifies an '@SQLRestriction' but it is a subclass in an entity inheritance hierarchy (only a root class may be specify a restriction)

What it means

Error "Entity class '${className}' specifies an '@SQLRestriction' but it is a subclass in an entity inheritance hierarchy (only a root class may be specify a restriction)" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java:1463

		else {
			checkSubclassEntity();
		}

		ensureNoMutabilityPlan();

		registerImportName();

		processNamedEntityGraphs();
	}

	private void checkSubclassEntity() {
		if ( !isMutable() ) {
			throw new AnnotationException( "Entity class '" + annotatedClass.getName()
					+ "' is annotated '@Immutable' but it is a subclass in an entity inheritance hierarchy"
					+ " (only a root class may declare its mutability)" );
		}
		if ( isNotBlank( where ) ) {
			throw new AnnotationException( "Entity class '" + annotatedClass.getName()
					+ "' specifies an '@SQLRestriction' but it is a subclass in an entity inheritance hierarchy"
					+ " (only a root class may be specify a restriction)" );
		}
	}

	private void ensureNoMutabilityPlan() {
		if ( annotatedClass.hasAnnotationUsage( Mutability.class, modelsContext() ) ) {
			throw new MappingException( "@Mutability is not allowed on entity" );
		}
	}

	private boolean isMutable() {
		return !annotatedClass.hasAnnotationUsage( Immutable.class, modelsContext() );
	}

	private void registerImportName() {
		try {
			final var metadataCollector = getMetadataCollector();

View on GitHub (pinned to fad1729dce)

Solutions

  1. Move @SQLRestriction to the root class of the entity inheritance hierarchy.

When it happens

Trigger: An annotation restricted to the root of an inheritance hierarchy is placed on a subclass (or the hierarchy rules are otherwise violated).

Common situations: SINGLE_TABLE/JOINED hierarchies where @Table, @DiscriminatorColumn, @DiscriminatorFormula, @Cache, @Immutable, @Id or @Version are declared on the wrong class of the hierarchy.


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/cfd9382d802f0d75. Report an issue: GitHub.