{"record":{"id":"7764d97a69ca9743","repo":"hibernate/hibernate-orm","slug":"identifier-of-an-instance-of-entityname-was-alte","errorCode":null,"errorMessage":"identifier of an instance of {entityName} was altered from {oldValue} to {newValue}","messagePattern":"identifier of an instance of (.+?) was altered from (.+?) to (.+?)","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/EnhancementAsProxyLazinessInterceptor.java","lineNumber":210,"sourceCode":"\n\t\tif ( meta.identifierAttributeNames.contains( attributeName ) ) {\n\t\t\t// it is illegal for the identifier value to be changed.  Normally Hibernate\n\t\t\t// validates this during flush.  However, here it's dangerous to just allow the\n\t\t\t// new value to be set and continue on waiting for the flush for validation\n\t\t\t// because this interceptor manages the entity's entry in the PC itself.  So\n\t\t\t// just do the check here up-front\n\t\t\tfinal boolean changed;\n\t\t\tif ( meta.nonAggregatedCidMapper == null ) {\n\t\t\t\tchanged = ! entityKey.getPersister().getIdentifierType().isEqual( oldValue, newValue );\n\t\t\t}\n\t\t\telse {\n\t\t\t\tfinal int subAttrIndex = meta.nonAggregatedCidMapper.getPropertyIndex( attributeName );\n\t\t\t\tfinal var subAttrType = meta.nonAggregatedCidMapper.getSubtypes()[subAttrIndex];\n\t\t\t\tchanged = ! subAttrType.isEqual( oldValue, newValue );\n\t\t\t}\n\n\t\t\tif ( changed ) {\n\t\t\t\tthrow new HibernateException( \"identifier of an instance of \" + entityKey.getEntityName()\n\t\t\t\t\t\t+ \" was altered from \" + oldValue + \" to \" + newValue );\n\t\t\t}\n\n\t\t\t// otherwise, setId has been called but passing in the same value - just pass it through\n\t\t\treturn newValue;\n\t\t}\n\n\t\tif ( meta.initializeBeforeWrite\n\t\t\t\t|| meta.collectionAttributeNames != null && meta.collectionAttributeNames.contains( attributeName ) ) {\n\t\t\t// we need to force-initialize the proxy - the fetch group to which the `attributeName` belongs\n\t\t\ttry {\n\t\t\t\tforceInitialize( target, attributeName );\n\t\t\t}\n\t\t\tfinally {\n\t\t\t\tsetInitialized();\n\t\t\t}\n\n\t\t\tif ( meta.inLineDirtyChecking ) {","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/EnhancementAsProxyLazinessInterceptor.java#L192-L228","documentation":"Error \"identifier of an instance of {entityName} was altered from {oldValue} to {newValue}\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Bytecode enhancement, proxy creation, or lazy interception is applied to an incompatible class or configuration.","commonSituations":"Build-time enhancement with module-system restrictions, mismatched Hibernate versions between build and runtime, or hibernate.bytecode.provider=none with a model that needs proxies.","solutions":["Do not change the identifier of a managed entity; create a new entity with the new id instead, or use a mutable business key separate from @Id."],"exampleFix":"Do not change the identifier of a managed entity; create a new entity with the new id instead, or use a mutable business key separate from @Id.","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"}