{"record":{"id":"df9912fda0b3ddaa","repo":"hibernate/hibernate-orm","slug":"merge-requested-with-id-not-matching-id-of-passed","errorCode":null,"errorMessage":"merge requested with id not matching id of passed entity","messagePattern":"merge requested with id not matching id of passed entity","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java","lineNumber":561,"sourceCode":"\t\telse {\n\t\t\treturn target;\n\t\t}\n\t}\n\n\t@Nullable\n\tprivate static Object getDetachedEntityId(\n\t\t\t@Nonnull MergeEvent event,\n\t\t\t@Nullable Object originalId,\n\t\t\t@Nonnull EntityPersister persister) {\n\t\tfinal var source = event.getSession();\n\t\tfinal Object id = event.getRequestedId();\n\t\tif ( id == null ) {\n\t\t\treturn originalId;\n\t\t}\n\t\telse {\n\t\t\t// check that entity id = requestedId\n\t\t\tif ( !persister.getIdentifierType().isEqual( id, originalId, source.getFactory() ) ) {\n\t\t\t\tthrow new HibernateException( \"merge requested with id not matching id of passed entity\" );\n\t\t\t}\n\t\t\treturn id;\n\t\t}\n\t}\n\n\t@Nonnull\n\tprivate static Object unproxyManagedForDetachedMerging(\n\t\t\t@Nonnull Object incoming,\n\t\t\t@Nonnull Object managed,\n\t\t\t@Nonnull EntityPersister persister,\n\t\t\t@Nonnull EventSource source) {\n\t\tif ( isHibernateProxy( managed ) ) {\n\t\t\treturn assertInitialized( managed );\n\t\t}\n\n\t\tif ( isPersistentAttributeInterceptable( incoming )\n\t\t\t\t&& persister.getBytecodeEnhancementMetadata().isEnhancedForLazyLoading() ) {\n","sourceCodeStart":543,"sourceCodeEnd":579,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java#L543-L579","documentation":"Error \"merge requested with id not matching id of passed entity\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when a merge is explicitly given an id that differs from the id of the passed entity instance.","commonSituations":"Typical situations: copy/paste of ids between entities; wrong entity passed together with an id from another instance.","solutions":["Do not change the id of the entity being merged to a value different from the one requested.","Pass the entity whose id matches the id used to look up the managed copy."],"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"}