hibernate/hibernate-orm · error · UnsupportedOperationException
Avoid this operation: does not perform well
Error message
Avoid this operation: does not perform well
What it means
IdentityMap keys entries by object identity (==) wrapped in IdentityKey. A containsValue(value) call has no index to use — it would have to scan every entry — so Hibernate explicitly disables it with UnsupportedOperationException instead of quietly offering a deceptively slow operation. This is a deliberate API design choice, not a transient failure.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/internal/util/collections/IdentityMap.java:95
@Override
public int size() {
return map.size();
}
@Override
public boolean isEmpty() {
return map.isEmpty();
}
@Override
public boolean containsKey(Object key) {
return map.containsKey( new IdentityKey<>( key ) );
}
@Override
public boolean containsValue(Object val) {
throw new UnsupportedOperationException( "Avoid this operation: does not perform well" );
//return map.containsValue( val );
}
@Override
public V get(Object key) {
return map.get( new IdentityKey<>( key ) );
}
@Override
public V put(K key, V value) {
this.entryArray = null;
return map.put( new IdentityKey<>( key ), value );
}
@Override
public V remove(Object key) {
this.entryArray = null;
return map.remove( new IdentityKey<>( key ) );View on GitHub (pinned to fad1729dce)
Solutions
- Do not call containsValue on identity-keyed Hibernate maps; ask the question differently (key-based lookup)
- If you truly need it, iterate values() yourself so the cost is explicit
- Filter IdentityMap instances out before generic Map processing
Example fix
// before
boolean present = identityMap.containsValue( value );
// after: explicit scan, cost visible at the call site
boolean present = false;
for ( V v : identityMap.values() ) {
if ( Objects.equals( value, v ) ) { present = true; break; }
} Defensive patterns
Strategy: type-guard
Validate before calling
// Ask the question without containsValue
static <K, V> boolean containsValueSlow(Map<K, V> map, V value) {
for ( V v : map.values() ) {
if ( Objects.equals( value, v ) ) return true;
}
return false;
} Type guard
static boolean supportsContainsValue(Map<?, ?> map) {
return !( map instanceof org.hibernate.internal.util.collections.IdentityMap );
} Try / catch
try {
map.containsValue( v );
} catch ( UnsupportedOperationException e ) {
// identity-keyed map: fall back to an explicit values() scan
} Prevention
- Assume Hibernate-internal Maps may not implement the full Map contract
- Prefer key-based lookups over value scans on identity maps
- Wrap received maps in your own adapter that implements containsValue via values() if generic code needs it
When it happens
Trigger: Calling containsValue(...) on an IdentityMap (or on a Map view obtained from Hibernate internals that is implemented by IdentityMap); generic Map-processing utility code that calls the full Map interface including containsValue.
Common situations: Custom diagnostics or instrumentation that walks persistence-context-related maps as plain java.util.Map and assumes every method is supported; generic helper methods like 'mapHasValue(Map m, Object v)' applied to an IdentityMap.
Related errors
- format() function not supported on Sybase
- cannot recreate collection while filter is enabled: " + coll
- Decomposition not supported for %s
- cannot recreate collection while filter is enabled [%s : %s]
- null key for collection: %s
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/64d39eb3d1a838a5.
Report an issue: GitHub.