{"record":{"id":"bf70bf00e5733390","repo":"hibernate/hibernate-orm","slug":"immutable-attribute-s-of-entity-s-was-modifi","errorCode":null,"errorMessage":"Immutable attribute '%s' of entity '%s' was modified (mark the field non-'final' or remove the '@Immutable' annotation)","messagePattern":"Immutable attribute '(.+?)' of entity '(.+?)' was modified \\(mark the field non-'final' or remove the '@Immutable' annotation\\)","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java","lineNumber":508,"sourceCode":"\t\t\t\t\t() -> interceptor.postMerge( entity, target, id, targetValues, originalValues, propertyNames, propertyTypes ) );\n\t\t\t//copyValues works by reflection, so explicitly mark the entity instance dirty\n\t\t\tmarkInterceptorDirty( entity, target );\n\t\t\tevent.setResult( result );\n\t\t}\n\t}\n\n\tprivate void verifyImmutableAttributes(\n\t\t\t@Nonnull EntityPersister persister,\n\t\t\t@Nonnull Object[] sourceValues,\n\t\t\t@Nonnull Object[] targetValues,\n\t\t\t@Nonnull EventSource session) {\n\t\tfor ( int i : persister.getImmutablePropertyIndexes() ) {\n\t\t\tfinal Object sourceValue = sourceValues[i];\n\t\t\tfinal Object targetValue = targetValues[i];\n\t\t\tif ( sourceValue != UNFETCHED_PROPERTY && targetValue != UNFETCHED_PROPERTY ) {\n\t\t\t\tif ( !persister.getPropertyTypes()[i]\n\t\t\t\t\t\t.isEqual( sourceValue, targetValue, session.getFactory() ) ) {\n\t\t\t\t\tthrow new HibernateException( \"Immutable attribute '%s' of entity '%s' was modified\"\n\t\t\t\t\t\t\t.formatted( persister.getPropertyNames()[i], persister.getEntityName() )\n\t\t\t\t\t\t\t\t\t+ \" (mark the field non-'final' or remove the '@Immutable' annotation)\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t@Nonnull\n\tprivate static Object targetEntity(\n\t\t\t@Nonnull MergeEvent event,\n\t\t\t@Nonnull Object entity,\n\t\t\t@Nonnull EntityPersister persister,\n\t\t\t@Nullable Object id,\n\t\t\t@Nonnull Object result) {\n\t\tfinal var source = event.getSession();\n\t\tfinal String entityName = persister.getEntityName();\n\t\tfinal Object target = unproxyManagedForDetachedMerging( entity, result, persister, source );\n\t\tif ( target == entity) {","sourceCodeStart":490,"sourceCodeEnd":526,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java#L490-L526","documentation":"Error \"Immutable attribute '%s' of entity '%s' was modified (mark the field non-'final' or remove the '@Immutable' annotation)\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when a change is detected on an attribute or entity mapped as immutable.","commonSituations":"Typical situations: modifying a field annotated @Immutable; dirty-checking detecting a mutation on an immutable attribute during merge/flush.","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."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}