{"record":{"id":"ed4ee9179a448eb8","repo":"hibernate/hibernate-orm","slug":"identifier-of-an-instance-of-persister-getentit","errorCode":null,"errorMessage":"Identifier of an instance of '${persister.getEntityName()}' was altered from ${entryId} to ${currentId}","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/event/internal/DefaultFlushEntityEventListener.java","lineNumber":88,"sourceCode":"\t\t\tfinal Object currentId = persister.getIdentifier( object, session );\n\t\t\t// Small optimization: always try to avoid getIdentifierType().isEqual(..) when possible.\n\t\t\t// (However, it's not safe to invoke the equals() method as it might trigger side effects.)\n\t\t\tif ( entryId != currentId\n\t\t\t\t\t\t&& !entry.getStatus().isDeletedOrGone()\n\t\t\t\t\t\t&& !persister.getIdentifierType().isEqual( entryId, currentId, session.getFactory() ) ) {\n\t\t\t\tthrowIdentifiedAlteredException( persister, entryId, currentId );\n\t\t\t}\n\t\t}\n\t\t// else this is a situation where the entity id is assigned by a post-insert\n\t\t// generator and was saved outside the transaction, forcing it to be delayed\n\t}\n\n\t// Used by Hibernate Reactive\n\tprotected void throwIdentifiedAlteredException(\n\t\t\t@Nonnull EntityPersister persister,\n\t\t\t@Nonnull Object entryId,\n\t\t\t@Nonnull Object currentId) {\n\t\tthrow new HibernateException( \"Identifier of an instance of '\" + persister.getEntityName()\n\t\t\t\t\t\t\t\t\t+ \"' was altered from \" + entryId + \" to \" + currentId );\n\t}\n\n\tprivate void checkNaturalId(\n\t\t\t@Nonnull EntityPersister persister,\n\t\t\t@Nonnull Object entity,\n\t\t\t@Nonnull EntityEntry entry,\n\t\t\t@Nonnull Object[] current,\n\t\t\t@Nullable Object[] loaded,\n\t\t\t@Nonnull SessionImplementor session) {\n\t\tif ( !isUninitializedEnhanced( entity ) ) {\n\t\t\tfinal var naturalIdMapping = persister.getNaturalIdMapping();\n\t\t\tif ( naturalIdMapping != null && entry.getStatus() != Status.READ_ONLY ) {\n\t\t\t\tnaturalIdMapping.verifyFlushState( entry.getId(), current, loaded, session );\n\t\t\t}\n\t\t}\n\t}\n","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultFlushEntityEventListener.java#L70-L106","documentation":"Error \"Identifier of an instance of '${persister.getEntityName()}' was altered from ${entryId} to ${currentId}\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when dirty checking detects that a managed entity's identifier value was changed.","commonSituations":"Typical situations: assigning a new value to the @Id property of a persistent entity; reflection or deserialization altering the id field.","solutions":["Do not modify the identifier (@Id) property of a managed entity after it has been persisted; identifiers must be immutable.","If a new identifier is required, delete the old row and insert a new entity with the new id.","Check for code (setters, reflection, or deserialization) that assigns a new id to an already-persistent instance."],"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"}