{"record":{"id":"c3105b1bedb633b8","repo":"hibernate/hibernate-orm","slug":"null-merge-and-managed-entities-are-not-supported","errorCode":null,"errorMessage":"null merge and managed entities are not supported by ","messagePattern":"null merge and managed entities are not supported by ","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/event/spi/MergeContext.java","lineNumber":223,"sourceCode":"\t * Associates the specified merge entity with the specified managed entity in this MergeContext.\n\t * If this MergeContext already contains a cross-reference for {@code mergeEntity} when this\n\t * method is called, then <code>managedEntity</code> must be the same as what is already associated\n\t * with {@code mergeEntity}.\n\t *\n\t * @param mergeEntity the merge entity; must be non-null\n\t * @param managedEntity the managed entity; must be non-null\n\t * @param isOperatedOn indicates if the merge operation is performed on the mergeEntity.\n\t *\n\t * @return previous managed entity associated with specified merge entity, or null if\n\t * there was no mapping for mergeEntity.\n\t * @throws NullPointerException if mergeEntity or managedEntity is null\n\t * @throws IllegalArgumentException if {@code managedEntity} is not the same as the previous\n\t * managed entity associated with {@code mergeEntity}\n\t * @throws IllegalStateException if internal cross-references are out of sync,\n\t */\n\tpublic @Nullable Object put(@Nonnull Object mergeEntity, @Nonnull Object managedEntity, boolean isOperatedOn) {\n\t\tif ( mergeEntity == null || managedEntity == null ) {\n\t\t\tthrow new NullPointerException( \"null merge and managed entities are not supported by \" + getClass().getName() );\n\t\t}\n\n\t\tObject oldManagedEntity = mergeToManagedEntityXref.put( mergeEntity, managedEntity );\n\t\tBoolean oldOperatedOn = mergeEntityToOperatedOnFlagMap.put( mergeEntity, isOperatedOn );\n\t\t// If managedEntity already corresponds with a different merge entity, that means\n\t\t// that there are multiple entities being merged that correspond with managedEntity.\n\t\t// In the following, oldMergeEntity will be replaced with mergeEntity in managedToMergeEntityXref.\n\t\tObject oldMergeEntity = managedToMergeEntityXref.put( managedEntity, mergeEntity );\n\n\t\tif ( oldManagedEntity == null ) {\n\t\t\t// this is a new mapping for mergeEntity in mergeToManagedEntityXref\n\t\t\tif  ( oldMergeEntity != null ) {\n\t\t\t\t// oldMergeEntity was a different merge entity with the same corresponding managed entity;\n\t\t\t\tentityCopyObserver.entityCopyDetected( managedEntity, mergeEntity, oldMergeEntity, session );\n\t\t\t}\n\t\t\tif ( oldOperatedOn != null ) {\n\t\t\t\tthrow new IllegalStateException(\n\t\t\t\t\t\t\"MergeContext#mergeEntityToOperatedOnFlagMap contains a merge entity \" + printEntity( mergeEntity )","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/event/spi/MergeContext.java#L205-L241","documentation":"Error \"null merge and managed entities are not supported by \" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when a null key or value is put into the merge-to-managed mapping of a MergeContext.","commonSituations":"Typical situations: merging a graph containing null elements; cascade-merge reaching a null association or collection element.","solutions":["Ensure both the merge (detached) entity and its managed copy are non-null before operating on the merge context."],"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"}