hibernate/hibernate-orm · error · NullPointerException
null merge and managed entities are not supported by
Error message
null merge and managed entities are not supported by
What it means
MergeContext.put null-guard: either the merge entity or the managed entity (or both) was null when registering the cross-reference. NullPointerException sentinel; merge tracking cannot record null participants.
Solutions
- Ensure both the merge (detached) entity and its managed copy are non-null before operating on the merge context.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown when a null key or value is put into the merge-to-managed mapping of a MergeContext.
Common situations: Typical situations: merging a graph containing null elements; cascade-merge reaching a null association or collection element.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/c3105b1bedb633b8.
Report an issue: GitHub.
Appendix: source
Thrown at hibernate-core/src/main/java/org/hibernate/event/spi/MergeContext.java:223
* Associates the specified merge entity with the specified managed entity in this MergeContext.
* If this MergeContext already contains a cross-reference for {@code mergeEntity} when this
* method is called, then <code>managedEntity</code> must be the same as what is already associated
* with {@code mergeEntity}.
*
* @param mergeEntity the merge entity; must be non-null
* @param managedEntity the managed entity; must be non-null
* @param isOperatedOn indicates if the merge operation is performed on the mergeEntity.
*
* @return previous managed entity associated with specified merge entity, or null if
* there was no mapping for mergeEntity.
* @throws NullPointerException if mergeEntity or managedEntity is null
* @throws IllegalArgumentException if {@code managedEntity} is not the same as the previous
* managed entity associated with {@code mergeEntity}
* @throws IllegalStateException if internal cross-references are out of sync,
*/
public @Nullable Object put(@Nonnull Object mergeEntity, @Nonnull Object managedEntity, boolean isOperatedOn) {
if ( mergeEntity == null || managedEntity == null ) {
throw new NullPointerException( "null merge and managed entities are not supported by " + getClass().getName() );
}
Object oldManagedEntity = mergeToManagedEntityXref.put( mergeEntity, managedEntity );
Boolean oldOperatedOn = mergeEntityToOperatedOnFlagMap.put( mergeEntity, isOperatedOn );
// If managedEntity already corresponds with a different merge entity, that means
// that there are multiple entities being merged that correspond with managedEntity.
// In the following, oldMergeEntity will be replaced with mergeEntity in managedToMergeEntityXref.
Object oldMergeEntity = managedToMergeEntityXref.put( managedEntity, mergeEntity );
if ( oldManagedEntity == null ) {
// this is a new mapping for mergeEntity in mergeToManagedEntityXref
if ( oldMergeEntity != null ) {
// oldMergeEntity was a different merge entity with the same corresponding managed entity;
entityCopyObserver.entityCopyDetected( managedEntity, mergeEntity, oldMergeEntity, session );
}
if ( oldOperatedOn != null ) {
throw new IllegalStateException(
"MergeContext#mergeEntityToOperatedOnFlagMap contains a merge entity " + printEntity( mergeEntity )View on GitHub (pinned to fad1729dce)