hibernate/hibernate-orm · error · HibernateException
Entity [%s] did not define a natural id
Error message
Entity [%s] did not define a natural id
What it means
Error "Entity [%s] did not define a natural id" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/loader/internal/BaseNaturalIdLoadAccessImpl.java:55
public abstract class BaseNaturalIdLoadAccessImpl<T> implements NaturalIdLoadOptions {
private final StatefulLoadAccessContext context;
private final EntityMappingType entityDescriptor;
private LockOptions lockOptions;
private boolean synchronizationEnabled = true;
private Set<String> enabledFetchProfiles;
private Set<String> disabledFetchProfiles;
private RootGraphImplementor<T> rootGraph;
private GraphSemantic graphSemantic;
protected BaseNaturalIdLoadAccessImpl(StatefulLoadAccessContext context, EntityMappingType entityDescriptor) {
this.context = context;
this.entityDescriptor = entityDescriptor;
if ( entityDescriptor.getNaturalIdMapping() == null ) {
throw new HibernateException(
String.format( "Entity [%s] did not define a natural id", entityDescriptor.getEntityName() )
);
}
}
public LockOptions getLockOptions() {
return lockOptions;
}
protected Object with(LockMode lockMode, PessimisticLockScope lockScope) {
if ( lockOptions == null ) {
lockOptions = new LockOptions();
}
lockOptions.setLockMode( lockMode );
lockOptions.setLockScope( lockScope );
return this;
}
View on GitHub (pinned to fad1729dce)
Solutions
- Map a natural id (@NaturalId) on the entity, or load by id instead of naturalId().
When it happens
Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/loader/internal/BaseNaturalIdLoadAccessImpl.java:55 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/399cf3f9fbee9383.
Report an issue: GitHub.