hibernate/hibernate-orm · error · IllegalStateException
Cannot make an entity of immutable type '{}' modifiable
Error message
Cannot make an entity of immutable type '{}' modifiable What it means
Error "Cannot make an entity of immutable type '{}' modifiable" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/engine/internal/EntityEntryImpl.java:447
@Override
public boolean isReadOnly() {
final Status status = getStatus();
if ( status != MANAGED && status != READ_ONLY ) {
throw new HibernateException("instance was not in a valid state");
}
return status == READ_ONLY;
}
@Override
public boolean setReadOnly(boolean readOnly, Object entity) {
final boolean changed = readOnly != isReadOnly();
if ( changed ) {
if ( readOnly ) {
setStatus( READ_ONLY );
loadedState = null;
}
else if ( !persister.isMutable() ) {
throw new IllegalStateException( "Cannot make an entity of immutable type '"
+ persister.getEntityName() + "' modifiable" );
}
else {
setStatus( MANAGED );
loadedState = persister.getValues( entity );
final var context = getPersistenceContext();
TypeHelper.deepCopy(
loadedState,
persister.getPropertyTypes(),
persister.getPropertyCheckability(),
loadedState,
context.getSession()
);
if ( persister.hasNaturalIdentifier() ) {
context.getNaturalIdResolutions().manageLocalResolution(
id,
persister.getNaturalIdMapping().extractNaturalIdFromEntityState( loadedState ),
persister,View on GitHub (pinned to fad1729dce)
Solutions
- Do not call setReadOnly(false) or make modifiable on an @Immutable entity
- Remove the @Immutable annotation if the entity must be mutable
When it happens
Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/engine/internal/EntityEntryImpl.java:447 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/bfda3c5b6a284739.
Report an issue: GitHub.