{"record":{"id":"c407f91496f7be21","repo":"hibernate/hibernate-orm","slug":"a-different-object-with-the-same-identifier-value-c407f9","errorCode":null,"errorMessage":"A different object with the same identifier value was already associated with this persistence context","messagePattern":"A different object with the same identifier value was already associated with this persistence context","errorType":"exception","errorClass":"NonUniqueObjectException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java","lineNumber":209,"sourceCode":"\t\t\tfinal var session = event.getSession();\n\t\t\tif ( session.getPersistenceContextInternal().getEntry( instanceToLoad ) != null ) {\n\t\t\t\tthrow new PersistentObjectException(\n\t\t\t\t\t\t\"attempted to load into an instance that was already associated with the session: \"\n\t\t\t\t\t\t\t\t+ infoString( persister, event.getEntityId(), event.getFactory() )\n\t\t\t\t);\n\t\t\t}\n\t\t\tpersister.setIdentifier( instanceToLoad, event.getEntityId(), session );\n\t\t}\n\n\t\tfinal Object entity = doLoad( event, persister, keyToLoad, options );\n\t\tfinal boolean isOptionalInstance = instanceToLoad != null;\n\t\tif ( entity == null\n\t\t\t\t&& ( !options.isAllowNulls() || isOptionalInstance ) ) {\n\t\t\tevent.getFactory().getEntityNotFoundDelegate()\n\t\t\t\t\t.handleEntityNotFound( event.getEntityClassName(), event.getEntityId() );\n\t\t}\n\t\telse if ( isOptionalInstance && entity != instanceToLoad ) {\n\t\t\tthrow new NonUniqueObjectException( event.getEntityId(), event.getEntityClassName() );\n\t\t}\n\t\treturn entity;\n\t}\n\n\t/**\n\t * Based on configured options, will either return a pre-existing proxy,\n\t * generate a new proxy, or perform an actual load.\n\t *\n\t * @param event The initiating load request event\n\t * @param persister The persister corresponding to the entity to be loaded\n\t * @param keyToLoad The key of the entity to be loaded\n\t * @param options The defined load options\n\t *\n\t * @return The result of the proxy/load operation.\n\t */\n\t@Nullable\n\tprivate Object proxyOrLoad(\n\t\t\t@Nonnull LoadEvent event,","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java#L191-L227","documentation":"Error \"A different object with the same identifier value was already associated with this persistence context\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when two distinct object instances with the same persistent identity would coexist in one persistence context.","commonSituations":"Typical situations: loading an entity while a detached copy with the same id is re-attached; merging a copy while the managed instance is already present; duplicate instances produced by manual construction.","solutions":["Use merge() instead of persist()/load() when a detached instance with the same identifier may already be in the persistence context.","Call session.clear() or evict() the conflicting instance before reattaching.","Ensure each entity with a given id is loaded only once per session."],"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"}