hibernate/hibernate-orm · error · HibernateException
Immutable attribute '%s' of entity '%s' was modified (mark t
Error message
Immutable attribute '%s' of entity '%s' was modified (mark the field non-'final' or remove the '@Immutable' annotation)
What it means
Error "Immutable attribute '%s' of entity '%s' was modified (mark the field non-'final' or remove the '@Immutable' annotation)" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java:508
() -> interceptor.postMerge( entity, target, id, targetValues, originalValues, propertyNames, propertyTypes ) );
//copyValues works by reflection, so explicitly mark the entity instance dirty
markInterceptorDirty( entity, target );
event.setResult( result );
}
}
private void verifyImmutableAttributes(
@Nonnull EntityPersister persister,
@Nonnull Object[] sourceValues,
@Nonnull Object[] targetValues,
@Nonnull EventSource session) {
for ( int i : persister.getImmutablePropertyIndexes() ) {
final Object sourceValue = sourceValues[i];
final Object targetValue = targetValues[i];
if ( sourceValue != UNFETCHED_PROPERTY && targetValue != UNFETCHED_PROPERTY ) {
if ( !persister.getPropertyTypes()[i]
.isEqual( sourceValue, targetValue, session.getFactory() ) ) {
throw new HibernateException( "Immutable attribute '%s' of entity '%s' was modified"
.formatted( persister.getPropertyNames()[i], persister.getEntityName() )
+ " (mark the field non-'final' or remove the '@Immutable' annotation)");
}
}
}
}
@Nonnull
private static Object targetEntity(
@Nonnull MergeEvent event,
@Nonnull Object entity,
@Nonnull EntityPersister persister,
@Nullable Object id,
@Nonnull Object result) {
final var source = event.getSession();
final String entityName = persister.getEntityName();
final Object target = unproxyManagedForDetachedMerging( entity, result, persister, source );
if ( target == entity) {View on GitHub (pinned to fad1729dce)
Solutions
- Do not modify attributes of an @Immutable entity; treat it as read-only.
- Remove the @Immutable annotation (or make the field non-final) if the attribute must be mutable.
When it happens
Trigger: Thrown when a change is detected on an attribute or entity mapped as immutable.
Common situations: Typical situations: modifying a field annotated @Immutable; dirty-checking detecting a mutation on an immutable attribute during merge/flush.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/bf70bf00e5733390.
Report an issue: GitHub.