{"record":{"id":"aa23ea413fab45d6","repo":"hibernate/hibernate-orm","slug":"an-immutable-attribute-s-within-compound-natura","errorCode":null,"errorMessage":"An immutable attribute [%s] within compound natural identifier of entity %s was altered from `%s` to `%s`","messagePattern":"An immutable attribute \\[(.+?)\\] within compound natural identifier of entity (.+?) was altered from `(.+?)` to `(.+?)`","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CompoundNaturalIdMapping.java","lineNumber":231,"sourceCode":"\t\tif ( !isMutable() ) {\n\t\t\tfinal var persistenceContext = session.getPersistenceContextInternal();\n\t\t\tfinal var persister = getDeclaringType().getEntityPersister();\n\n\t\t\tfinal Object[] naturalId = extractNaturalIdFromEntityState( currentState );\n\t\t\tfinal Object snapshot = loadedState == null\n\t\t\t\t\t? persistenceContext.getNaturalIdSnapshot( id, persister )\n\t\t\t\t\t: persister.getNaturalIdMapping().extractNaturalIdFromEntityState( loadedState );\n\t\t\tfinal Object[] previousNaturalId = (Object[]) snapshot;\n\t\t\tassert naturalId.length == getNaturalIdAttributes().size();\n\t\t\tassert previousNaturalId.length == naturalId.length;\n\n\t\t\tfor ( int i = 0; i < getNaturalIdAttributes().size(); i++ ) {\n\t\t\t\tfinal var attributeMapping = getNaturalIdAttributes().get( i );\n\t\t\t\tif ( !attributeMapping.getAttributeMetadata().isUpdatable() ) {\n\t\t\t\t\tfinal Object currentValue = naturalId[i];\n\t\t\t\t\tfinal Object previousValue = previousNaturalId[i];\n\t\t\t\t\tif ( !attributeMapping.areEqual( currentValue, previousValue, session ) ) {\n\t\t\t\t\t\tthrow new HibernateException(\n\t\t\t\t\t\t\t\tString.format(\n\t\t\t\t\t\t\t\t\t\t\"An immutable attribute [%s] within compound natural identifier of entity %s was altered from `%s` to `%s`\",\n\t\t\t\t\t\t\t\t\t\tattributeMapping.getAttributeName(),\n\t\t\t\t\t\t\t\t\t\tpersister.getEntityName(),\n\t\t\t\t\t\t\t\t\t\tpreviousValue,\n\t\t\t\t\t\t\t\t\t\tcurrentValue\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// else property is updatable (mutable), there is nothing to check\n\t\t\t}\n\t\t}\n\t\t// otherwise the natural id is mutable (!immutable), no need to do the checks\n\t}\n\n\t@Override\n\tpublic boolean areEqual(Object one, Object other, SharedSessionContractImplementor session) {","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CompoundNaturalIdMapping.java#L213-L249","documentation":"Error \"An immutable attribute [%s] within compound natural identifier of entity %s was altered from `%s` to `%s`\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at flush time when an attribute marked immutable within a compound natural id has been changed between snapshots.","commonSituations":"See trigger scenarios.","solutions":["Do not modify attributes that are part of an immutable (non-mutable) natural id; create a new entity instead.","Mark the natural id as mutable (mutable=true) if changes are intended."],"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"}