{"record":{"id":"41de45d56a3146e4","repo":"hibernate/hibernate-orm","slug":"object-passed-to-upsert-has-no-identifier","errorCode":null,"errorMessage":"Object passed to upsert() has no identifier","messagePattern":"Object passed to upsert\\(\\) has no identifier","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java","lineNumber":852,"sourceCode":"\t\t\t\treturn state[persister.getVersionPropertyIndex()];\n\t\t\t}\n\t\t\telse {\n\t\t\t\tfinal Object newVersion = incrementVersion( entity, oldVersion, persister, this );\n\t\t\t\tsetVersion( state, newVersion, persister );\n\t\t\t\tpersister.setValues( entity, state );\n\t\t\t\treturn oldVersion;\n\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 );","sourceCodeStart":834,"sourceCodeEnd":870,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java#L834-L870","documentation":"Error \"Object passed to upsert() has no identifier\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java:852 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set a non-null identifier on the entity before calling upsert(), or use insert() for new entities without ids."],"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"}