hibernate/hibernate-orm · error · IdentifierGenerationException
Could not assign id from null association '
Error message
Could not assign id from null association '
What it means
Error "Could not assign id from null association '" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/id/IdentifierGeneratorHelper.java:117
if ( sessionImplementor.isManaged( object ) ) {
//abort the save (the object is already saved by a circular cascade)
return SHORT_CIRCUIT_INDICATOR;
//throw new IdentifierGenerationException("save associated object first, or disable cascade for inverse association");
}
else {
final var persister =
sessionImplementor.getFactory().getMappingMetamodel()
.getEntityDescriptor( entityName );
return identifier( sessionImplementor, entityType( propertyName, persister ),
associatedEntity( entityName, propertyName, object, persister ) );
}
}
private static Object associatedEntity(
String entityName, String propertyName, Object object, EntityPersister entityDescriptor) {
final Object associatedObject = entityDescriptor.getPropertyValue( object, propertyName );
if ( associatedObject == null ) {
throw new IdentifierGenerationException( "Could not assign id from null association '" + propertyName
+ "' of entity '" + entityName + "'" );
}
return associatedObject;
}
private static Object identifier(
SharedSessionContractImplementor session,
EntityType foreignValueSourceType,
Object associatedEntity) {
final String associatedEntityName = foreignValueSourceType.getAssociatedEntityName();
try {
return getEntityIdentifierIfNotUnsaved( associatedEntityName, associatedEntity, session );
}
catch (TransientObjectException toe) {
if ( session instanceof Session statefulSession ) {
statefulSession.persist( associatedEntityName, associatedEntity );
return session.getContextEntityIdentifier( associatedEntity );
}View on GitHub (pinned to fad1729dce)
Solutions
- Ensure the associated entity referenced for id derivation is set and non-null before persisting.
- Persist or load the parent/associated entity first so the foreign id can be derived.
When it happens
Trigger: Thrown when a foreign id generator cannot obtain the id from the associated entity.
Common situations: Typical situations: missing 'property' param on the foreign generator; the association is null when the id is generated.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/fa85742a2aa25390.
Report an issue: GitHub.