{"record":{"id":"82218640f2381b1c","repo":"hibernate/hibernate-orm","slug":"object-passed-to-upsert-has-an-unsaved-identifie","errorCode":null,"errorMessage":"Object passed to upsert() has an unsaved identifier value: \" + persister.getEntityName()","messagePattern":"Object passed to upsert\\(\\) has an unsaved identifier value: \" \\+ persister\\.getEntityName\\(\\)","errorType":"exception","errorClass":"TransientObjectException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java","lineNumber":859,"sourceCode":"\t\t\t}\n\t\t}\n\t\telse {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t// Hibernate Reactive calls this\n\tprotected Object idToUpsert(Object entity, EntityPersister persister) {\n\t\tfinal Object id = persister.getIdentifier( entity, this );\n\t\tif ( id == null ) {\n\t\t\tthrow new IllegalArgumentException( \"Object passed to upsert() has no identifier\" );\n\t\t}\n\t\tfinal Boolean unsaved =\n\t\t\t\tpersister.getIdentifierMapping()\n\t\t\t\t\t\t.getUnsavedStrategy()\n\t\t\t\t\t\t.isUnsaved( id );\n\t\tif ( unsaved != null && unsaved ) {\n\t\t\tthrow new TransientObjectException( \"Object passed to upsert() has an unsaved identifier value: \"\n\t\t\t\t\t+ persister.getEntityName() );\n\t\t}\n\t\treturn id;\n\t}\n\n\t// event processing ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n\t// Hibernate Reactive may need to call this\n\tprotected boolean firePreInsert(Object entity, Object id, Object[] state, EntityPersister persister) {\n\t\tfinal var callbacks = persister.getEntityCallbacks();\n\t\tfinal boolean hasPrePersistCallbacks = callbacks.hasRegisteredCallbacks( CallbackType.PRE_PERSIST );\n\t\tfinal boolean hasPreInsertCallbacks = callbacks.hasRegisteredCallbacks( CallbackType.PRE_INSERT );\n\t\tif ( ( hasPrePersistCallbacks || hasPreInsertCallbacks )\n\t\t\t\t&& callEntityLifecycleCallback( () -> {\n\t\t\t\t\tfinal boolean prePersist = hasPrePersistCallbacks && callbacks.preCreate( entity );\n\t\t\t\t\treturn hasPreInsertCallbacks && callbacks.preInsert( entity ) || prePersist;\n\t\t\t\t} ) ) {\n\t\t\tcopyStateFromEntity( entity, state, persister );","sourceCodeStart":841,"sourceCodeEnd":877,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java#L841-L877","documentation":"Error \"Object passed to upsert() has an unsaved identifier value: \" + persister.getEntityName()\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java:859 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Assign a proper saved identifier value before upsert(); the current id matches the entity's unsaved-value marker, so Hibernate treats it as transient.","Adjust the unsaved-value configuration or persist the entity first."],"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"}