{"record":{"id":"8398c1ca15840b3a","repo":"hibernate/hibernate-orm","slug":"deleted-instance-passed-to-merge","errorCode":null,"errorMessage":"deleted instance passed to merge","messagePattern":"deleted instance passed to merge","errorType":"exception","errorClass":"ObjectDeletedException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java","lineNumber":219,"sourceCode":"\t\t\t\tentityIsTransient( event, copiedId != null ? copiedId : originalId, copiedAlready );\n\t\t\t\tbreak;\n\t\t\tcase PERSISTENT:\n\t\t\t\tentityIsPersistent( event, copiedAlready );\n\t\t\t\tbreak;\n\t\t\tdefault: //DELETED\n\t\t\t\tif ( persistenceContext.getEntry( entity ) == null ) {\n\t\t\t\t\tfinal var persister = source.getEntityPersister( entityName, entity );\n\t\t\t\t\tassert persistenceContext.containsDeletedUnloadedEntityKey(\n\t\t\t\t\t\t\tsource.generateEntityKey(\n\t\t\t\t\t\t\t\t\tpersister.getIdentifier( entity, event.getSession() ),\n\t\t\t\t\t\t\t\t\tpersister\n\t\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t\tsource.getActionQueue().unScheduleUnloadedDeletion( entity );\n\t\t\t\t\tentityIsDetached( event, copiedId, originalId, copiedAlready );\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tthrow new ObjectDeletedException( \"deleted instance passed to merge\",\n\t\t\t\t\t\toriginalId, getLoggableName( entityName, entity ) );\n\t\t}\n\t}\n\n\t@Nonnull\n\tprivate static Object copyCompositeTypeId(\n\t\t\t@Nullable Object id,\n\t\t\t@Nonnull CompositeType compositeType,\n\t\t\t@Nonnull EventSource session,\n\t\t\t@Nonnull MergeContext mergeContext) {\n\t\tfinal var factory = session.getSessionFactory();\n\t\tfinal Object idCopy = compositeType.deepCopy( id, factory );\n\t\tfinal Type[] subtypes = compositeType.getSubtypes();\n\t\tfinal Object[] propertyValues = compositeType.getPropertyValues( id );\n\t\tfinal Object[] copiedValues = compositeType.getPropertyValues( idCopy );\n\t\tfor ( int i = 0; i < subtypes.length; i++ ) {\n\t\t\tcopiedValues[i] = copy( session, mergeContext, subtypes[i], propertyValues[i], factory );\n\t\t}","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java#L201-L237","documentation":"Error \"deleted instance passed to merge\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when an instance already marked for removal is reached again through cascading.","commonSituations":"Typical situations: a deleted entity still referenced from a collection of another managed entity; orphan-removal plus explicit delete of the same instance.","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."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}