hibernate/hibernate-orm · error · IdentifierGenerationException
Entity '{}' has no '@NaturalId' property
Error message
Entity '{}' has no '@NaturalId' property What it means
Error "Entity '{}' has no '@NaturalId' property" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/internal/NaturalIdHelper.java:24
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.engine.spi.Status;
import org.hibernate.id.IdentifierGenerationException;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.persister.entity.EntityPersister;
import static org.hibernate.engine.internal.NaturalIdLogging.NATURAL_ID_LOGGER;
import static org.hibernate.pretty.MessageHelper.infoString;
/**
* @author Gavin King
*/
public class NaturalIdHelper {
public static String[] getNaturalIdPropertyNames(EntityPersister persister) {
final int[] naturalIdPropertyIndices = persister.getNaturalIdentifierProperties();
if ( naturalIdPropertyIndices == null ) {
throw new IdentifierGenerationException( "Entity '" + persister.getEntityName()
+ "' has no '@NaturalId' property" );
}
if ( persister.isNaturalIdentifierInsertGenerated() ) {
throw new IdentifierGenerationException( "Entity '" + persister.getEntityName()
+ "' has a '@NaturalId' property which is also defined as insert-generated" );
}
final String[] allPropertyNames = persister.getPropertyNames();
final String[] propertyNames = new String[naturalIdPropertyIndices.length];
for ( int i = 0; i < naturalIdPropertyIndices.length; i++ ) {
propertyNames[i] = allPropertyNames[naturalIdPropertyIndices[i]];
}
return propertyNames;
}
public static void performAnyNeededCrossReferenceSynchronizations(
boolean synchronizationEnabled,
EntityMappingType entityMappingType,
SharedSessionContractImplementor session) {View on GitHub (pinned to fad1729dce)
Solutions
- Annotate a property of the entity with @NaturalId before using natural-id load access.
When it happens
Trigger: Thrown when a natural-id operation is requested on an entity without a valid @NaturalId mapping.
Common situations: Typical situations: calling byNaturalId() for an entity lacking @NaturalId; a natural id also mapped as insert-generated.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/ccbf17595f2bc15f.
Report an issue: GitHub.