{"record":{"id":"09e970c0c1ff9beb","repo":"hibernate/hibernate-orm","slug":"an-immutable-natural-identifier-of-entity-s-was-a","errorCode":null,"errorMessage":"An immutable natural identifier of entity %s was altered from `%s` to `%s`","messagePattern":"An immutable 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/SimpleNaturalIdMapping.java","lineNumber":76,"sourceCode":"\tpublic SingularAttributeMapping getAttribute() {\n\t\treturn attribute;\n\t}\n\n\t@Override\n\tpublic void verifyFlushState(\n\t\t\tObject id,\n\t\t\tObject[] currentState,\n\t\t\tObject[] loadedState,\n\t\t\tSharedSessionContractImplementor session) {\n\t\tif ( !isMutable() ) {\n\t\t\tfinal var persister = getDeclaringType().getEntityPersister();\n\t\t\tfinal Object naturalId = extractNaturalIdFromEntityState( currentState );\n\t\t\tfinal Object snapshot =\n\t\t\t\t\tloadedState == null\n\t\t\t\t\t\t\t? session.getPersistenceContextInternal().getNaturalIdSnapshot( id, persister )\n\t\t\t\t\t\t\t: persister.getNaturalIdMapping().extractNaturalIdFromEntityState( loadedState );\n\t\t\tif ( !areEqual( naturalId, snapshot, session ) ) {\n\t\t\t\tthrow new HibernateException(\n\t\t\t\t\t\tString.format(\n\t\t\t\t\t\t\t\t\"An immutable natural identifier of entity %s was altered from `%s` to `%s`\",\n\t\t\t\t\t\t\t\tpersister.getEntityName(),\n\t\t\t\t\t\t\t\tsnapshot,\n\t\t\t\t\t\t\t\tnaturalId\n\t\t\t\t\t\t)\n\t\t\t\t);\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 Object extractNaturalIdFromEntityState(Object[] state) {\n\t\tif ( state == null ) {\n\t\t\treturn null;\n\t\t}\n\t\telse if ( state.length == 1 ) {","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleNaturalIdMapping.java#L58-L94","documentation":"Error \"An immutable natural identifier of entity %s was altered from `%s` to `%s`\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at flush time when an entity's immutable simple natural id attribute has been changed compared to its loaded snapshot.","commonSituations":"See trigger scenarios.","solutions":["Do not change an immutable natural id; update other attributes only, or delete and re-create the entity with the new natural id.","Declare the natural id mutable if changes must be allowed."],"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"}