hibernate/hibernate-orm · error · NullPointerException
This store does not support null keys
Error message
This store does not support null keys
What it means
InstanceIdentityStore.put(Object key, int instanceId, V value) rejects null keys up front with NullPointerException and 'This store does not support null keys'. Entries are addressed by instanceId, but the key is stored alongside for identity verification (the k == key checks in get/remove), so a null key cannot be stored without breaking that verification.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/internal/util/collections/InstanceIdentityStore.java:81
throw new ConcurrentModificationException(
"Found a different instance corresponding to instanceId [" + instanceId +
"], this might indicate a concurrent access to this persistence context."
);
}
}
return null;
}
/**
* Associates the specified value with the specified key in this store (optional operation). If the store
* previously contained a mapping for the key, the old value is replaced by the specified value.
*
* @param key key with which the specified value is to be associated
* @param value value to be associated with the specified key
*/
public void put(Object key, int instanceId, V value) {
if ( key == null ) {
throw new NullPointerException( "This store does not support null keys" );
}
else if ( instanceId <= 0 ) {
throw new IllegalArgumentException( "Instance ID must be a positive value" );
}
final int keyIndex = toKeyIndex( instanceId );
final Page<Object> page = getOrCreateEntryPage( keyIndex );
final int pageOffset = toPageOffset( keyIndex );
page.set( pageOffset, key );
page.set( pageOffset + 1, value );
}
/**
* Removes the mapping for an instance id from this store if it is present (optional operation).
*
* @param instanceId the instance id whose associated value is to be returned
* @param key key instance to double-check instance equality
* @implNote This method accesses the backing array with the provided instance id, but performs an instanceView on GitHub (pinned to fad1729dce)
Solutions
- Check key != null before put and handle the missing-entity case explicitly
- Trace the null to its source — usually session.find/get on a deleted or never-existing row
- Do not 'fix' by passing a placeholder key; the identity checks would then throw elsewhere
Example fix
// before
store.put( entity, id, state );
// after
if ( entity == null ) {
return; // entity absent: nothing to cache
}
store.put( entity, id, state ); Defensive patterns
Strategy: validation
Validate before calling
Objects.requireNonNull( key, "entity key must not be null" ); store.put( key, instanceId, value );
Prevention
- Check entity references for null right after load/find, before caching them
- Model 'entity not found' explicitly instead of storing null keys
- Fail fast with a descriptive message at your own API boundary rather than letting the store throw
When it happens
Trigger: put(null, instanceId, value) — an entity reference that is null because a preceding load/find returned null (row absent) or a variable was never assigned.
Common situations: Cache-fill code that puts the result of session.get() without a null check for missing rows; refactoring that turned a guaranteed non-null key into an Optional-unwrapped null.
Related errors
- This map does not support null keys
- Instance ID must be a positive value
- Instance ID must be a positive value
- null key for collection: %s
- null key for collection: %s
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/e72d3895974608d8.
Report an issue: GitHub.