hibernate/hibernate-orm · error · HibernateException
Immutable collection was modified: ${collectionInfo}
Error message
Immutable collection was modified: ${collectionInfo} What it means
Error "Immutable collection was modified: ${collectionInfo}" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/engine/spi/CollectionEntry.java:179
|| loadedPersister.getElementType().isMutable();
}
private boolean isModifiable() {
return !readOnly
&& loadedPersister != null
&& loadedPersister.isMutable();
}
public void preFlush(PersistentCollection<?> collection) {
if ( loadedKey == null ) {
loadedKey = collection.getKey();
}
final var loadedPersister = this.loadedPersister;
if ( collection.isDirty()
&& loadedPersister != null
&& !isModifiable() ) {
throw new HibernateException( "Immutable collection was modified: " +
collectionInfoString( loadedPersister.getRole(), getLoadedKey() ) );
}
dirty( collection );
if ( CORE_LOGGER.isTraceEnabled()
&& loadedPersister != null
&& collection.isDirty() ) {
CORE_LOGGER.collectionDirty(
collectionInfoString( loadedPersister.getRole(), getLoadedKey() ) );
}
}
public void postInitialize(PersistentCollection<?> collection, SharedSessionContractImplementor session) {
final var loadedPersister = this.loadedPersister;
snapshot = loadedPersister != null && isModifiable() ? collection.getSnapshot( loadedPersister ) : null;
collection.setSnapshot( loadedKey, role, snapshot );
if ( loadedPersister != nullView on GitHub (pinned to fad1729dce)
Solutions
- Do not modify a collection mapped as immutable; replace it or make the mapping mutable
- Remove the immutability restriction from the collection mapping
When it happens
Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/engine/spi/CollectionEntry.java:179 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/3bf3b2d485dc5547.
Report an issue: GitHub.