hibernate/hibernate-orm · error · IllegalArgumentException
Could not determine identifier of proxy passed to evict()
Error message
Could not determine identifier of proxy passed to evict()
What it means
Error "Could not determine identifier of proxy passed to evict()" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/event/internal/DefaultEvictEventListener.java:51
* Handle the given evict event.
*
* @param event The evict event to be handled.
*
*/
@Override
public void onEvict(@Nonnull EvictEvent event) {
final var source = event.getSession();
final var persistenceContext = source.getPersistenceContextInternal();
final Object object = event.getObject();
//noinspection ConstantValue
if ( object == null ) {
throw new NullPointerException( "null passed to Session.evict()" );
}
final var lazyInitializer = extractLazyInitializer( object );
if ( lazyInitializer != null ) {
final Object id = lazyInitializer.getInternalIdentifier();
if ( id == null ) {
throw new IllegalArgumentException( "Could not determine identifier of proxy passed to evict()" );
}
final var persister =
source.getFactory().getMappingMetamodel()
.getEntityDescriptor( lazyInitializer.getEntityName() );
final var key = source.generateEntityKey( id, persister );
final var holder = persistenceContext.detachEntity( key );
// if the entity has been evicted then its holder is null
if ( holder != null && !lazyInitializer.isUninitialized() ) {
final Object entity = holder.getEntity();
if ( entity != null ) {
final var entry = persistenceContext.removeEntry( entity );
doEvict( entity, key, entry.getPersister(), event.getSession() );
}
}
lazyInitializer.unsetSession();
}
else {
final var entry = persistenceContext.getEntry( object );View on GitHub (pinned to fad1729dce)
Solutions
- Ensure the proxy passed to Session.evict() is initialized (Hibernate.initialize) so its identifier can be determined before evicting.
- Fetch the entity by id and evict the loaded instance instead of an uninitialized proxy.
- Check that the proxy's session is still open when evict() is called.
When it happens
Trigger: Thrown when evict() is called with a lazy proxy whose identifier cannot be determined.
Common situations: Typical situations: evicting an uninitialized proxy whose id was never assigned; a proxy created with a null id.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/0e841f10e7f08f02.
Report an issue: GitHub.