hibernate/hibernate-orm · error · AnnotationException

Entity '${entity}' has no identifier (every '@Entity' class

Error message

Entity '${entity}' has no identifier (every '@Entity' class must declare or inherit at least one '@Id' or '@EmbeddedId' property)

What it means

Error "Entity '${entity}' has no identifier (every '@Entity' class must declare or inherit at least one '@Id' or '@EmbeddedId' property)" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/InheritanceState.java:248

			getMappedSuperclassesTillNextEntityOrdered();

			final var defaultAccessType = determineDefaultAccessType();

			if ( classDetails.hasDirectAnnotationUsage( Access.class ) ) {
				accessType = getAccessStrategy( classDetails.getDirectAnnotationUsage( Access.class ).value() );
			}
			else {
				accessType = defaultAccessType;
			}

			final ArrayList<PropertyData> elements = new ArrayList<>();
			int idPropertyCount = 0;
			for ( var classToProcessForMappedSuperclass : classesToProcessForMappedSuperclass ) {
				final var container = new PropertyContainer( classToProcessForMappedSuperclass, classDetails, defaultAccessType );
				idPropertyCount = addElementsOfClass( elements, container, buildingContext, idPropertyCount );
			}
			if ( idPropertyCount == 0 && !inheritanceState.hasParents() ) {
				throw new AnnotationException( "Entity '" + classDetails.getName() + "' has no identifier"
						+ " (every '@Entity' class must declare or inherit at least one '@Id' or '@EmbeddedId' property)" );
			}
			elements.trimToSize();
			elementsToProcess = new ElementsToProcess( elements, idPropertyCount );
		}
		return elementsToProcess;
	}

	private AccessType determineDefaultAccessType() {

		// do not check for `@Access` to determine the default access type of the hierarchy

		final var idAccessType = determineAccessTypeFromId( classDetails );
		if ( idAccessType != null ) {
			return idAccessType;
		}

		// next consider the current class

View on GitHub (pinned to fad1729dce)

Solutions

  1. Declare an @Id or @EmbeddedId property on the entity or one of its superclasses.

When it happens

Trigger: A composite identifier mapping (@IdClass/@EmbeddedId/@MapsId) does not match the entity's persistent properties.

Common situations: Composite primary keys where the id class properties, their types, or @MapsId values drift out of sync with the entity, or an embeddable with inheritance is reused as an id.


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