hibernate/hibernate-orm · error · NonUniqueObjectException
A different object with the same identifier value was alread
Error message
A different object with the same identifier value was already associated with this persistence context for entity {infoString} What it means
Error "A different object with the same identifier value was already associated with this persistence context for entity {infoString}" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java:806
.$$_hibernate_getInterceptor();
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor lazinessInterceptor ) {
lazinessInterceptor.forceInitialize( maybeProxy, null );
}
return maybeProxy;
}
else {
return maybeProxy;
}
}
@Override
public void checkUniqueness(EntityKey key, Object object) throws HibernateException {
final Object entity = getEntity( key );
if ( entity == object ) {
throw new AssertionFailure( "object already associated, but no entry was found" );
}
if ( entity != null ) {
throw new NonUniqueObjectException( key.getIdentifier(), key.getEntityName() );
}
}
@Override
public Object narrowProxy(Object proxy, EntityPersister persister, EntityKey key, Object object)
throws HibernateException {
final var concreteProxyClass = persister.getConcreteProxyClass();
final boolean alreadyNarrow = concreteProxyClass.isInstance( proxy );
if ( !alreadyNarrow ) {
PERSISTENCE_CONTEXT_LOGGER.narrowingProxy( concreteProxyClass );
// If an impl is passed, there is really no point in creating a proxy.
// It would just be extra processing. Just return the impl
if ( object != null ) {
removeProxyByKey( key );
return object;View on GitHub (pinned to fad1729dce)
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
When it happens
Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java:806 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/c9c1b7123f197040.
Report an issue: GitHub.