{"record":{"id":"c9c1b7123f197040","repo":"hibernate/hibernate-orm","slug":"a-different-object-with-the-same-identifier-value","errorCode":null,"errorMessage":"A different object with the same identifier value was already associated with this persistence context for entity {infoString}","messagePattern":"A different object with the same identifier value was already associated with this persistence context for entity (.+?)","errorType":"exception","errorClass":"NonUniqueObjectException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java","lineNumber":806,"sourceCode":"\t\t\t\t\t\t\t.$$_hibernate_getInterceptor();\n\t\t\tif ( interceptor instanceof EnhancementAsProxyLazinessInterceptor lazinessInterceptor ) {\n\t\t\t\tlazinessInterceptor.forceInitialize( maybeProxy, null );\n\t\t\t}\n\t\t\treturn maybeProxy;\n\t\t}\n\t\telse {\n\t\t\treturn maybeProxy;\n\t\t}\n\t}\n\n\t@Override\n\tpublic void checkUniqueness(EntityKey key, Object object) throws HibernateException {\n\t\tfinal Object entity = getEntity( key );\n\t\tif ( entity == object ) {\n\t\t\tthrow new AssertionFailure( \"object already associated, but no entry was found\" );\n\t\t}\n\t\tif ( entity != null ) {\n\t\t\tthrow new NonUniqueObjectException( key.getIdentifier(), key.getEntityName() );\n\t\t}\n\t}\n\n\t@Override\n\tpublic Object narrowProxy(Object proxy, EntityPersister persister, EntityKey key, Object object)\n\t\t\tthrows HibernateException {\n\n\t\tfinal var concreteProxyClass = persister.getConcreteProxyClass();\n\t\tfinal boolean alreadyNarrow = concreteProxyClass.isInstance( proxy );\n\n\t\tif ( !alreadyNarrow ) {\n\t\t\tPERSISTENCE_CONTEXT_LOGGER.narrowingProxy( concreteProxyClass );\n\n\t\t\t// If an impl is passed, there is really no point in creating a proxy.\n\t\t\t// It would just be extra processing.  Just return the impl\n\t\t\tif ( object != null ) {\n\t\t\t\tremoveProxyByKey( key );\n\t\t\t\treturn object;","sourceCodeStart":788,"sourceCodeEnd":824,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java#L788-L824","documentation":"Error \"A different object with the same identifier value was already associated with this persistence context for entity {infoString}\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java:806 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use session.merge() instead of persist() when another instance with the same id is already loaded","Clear or evict the existing instance before associating a new object with the same identifier"],"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"}