hibernate/hibernate-orm · error · ObjectDeletedException
deleted instance passed to merge
Error message
deleted instance passed to merge
What it means
Error "deleted instance passed to merge" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java:219
entityIsTransient( event, copiedId != null ? copiedId : originalId, copiedAlready );
break;
case PERSISTENT:
entityIsPersistent( event, copiedAlready );
break;
default: //DELETED
if ( persistenceContext.getEntry( entity ) == null ) {
final var persister = source.getEntityPersister( entityName, entity );
assert persistenceContext.containsDeletedUnloadedEntityKey(
source.generateEntityKey(
persister.getIdentifier( entity, event.getSession() ),
persister
)
);
source.getActionQueue().unScheduleUnloadedDeletion( entity );
entityIsDetached( event, copiedId, originalId, copiedAlready );
break;
}
throw new ObjectDeletedException( "deleted instance passed to merge",
originalId, getLoggableName( entityName, entity ) );
}
}
@Nonnull
private static Object copyCompositeTypeId(
@Nullable Object id,
@Nonnull CompositeType compositeType,
@Nonnull EventSource session,
@Nonnull MergeContext mergeContext) {
final var factory = session.getSessionFactory();
final Object idCopy = compositeType.deepCopy( id, factory );
final Type[] subtypes = compositeType.getSubtypes();
final Object[] propertyValues = compositeType.getPropertyValues( id );
final Object[] copiedValues = compositeType.getPropertyValues( idCopy );
for ( int i = 0; i < subtypes.length; i++ ) {
copiedValues[i] = copy( session, mergeContext, subtypes[i], propertyValues[i], factory );
}View on GitHub (pinned to fad1729dce)
Solutions
- Do not call merge() on an entity that was deleted in the current session; remove the deleted instance from associations instead.
- Reload the entity from the database if it must be re-saved after deletion.
When it happens
Trigger: Thrown when an instance already marked for removal is reached again through cascading.
Common situations: Typical situations: a deleted entity still referenced from a collection of another managed entity; orphan-removal plus explicit delete of the same instance.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/8398c1ca15840b3a.
Report an issue: GitHub.