{"record":{"id":"0e841f10e7f08f02","repo":"hibernate/hibernate-orm","slug":"could-not-determine-identifier-of-proxy-passed-to","errorCode":null,"errorMessage":"Could not determine identifier of proxy passed to evict()","messagePattern":"Could not determine identifier of proxy passed to evict\\(\\)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/event/internal/DefaultEvictEventListener.java","lineNumber":51,"sourceCode":"\t * Handle the given evict event.\n\t *\n\t * @param event The evict event to be handled.\n\t *\n\t */\n\t@Override\n\tpublic void onEvict(@Nonnull EvictEvent event) {\n\t\tfinal var source = event.getSession();\n\t\tfinal var persistenceContext = source.getPersistenceContextInternal();\n\t\tfinal Object object = event.getObject();\n\t\t//noinspection ConstantValue\n\t\tif ( object == null ) {\n\t\t\tthrow new NullPointerException( \"null passed to Session.evict()\" );\n\t\t}\n\t\tfinal var lazyInitializer = extractLazyInitializer( object );\n\t\tif ( lazyInitializer != null ) {\n\t\t\tfinal Object id = lazyInitializer.getInternalIdentifier();\n\t\t\tif ( id == null ) {\n\t\t\t\tthrow new IllegalArgumentException( \"Could not determine identifier of proxy passed to evict()\" );\n\t\t\t}\n\t\t\tfinal var persister =\n\t\t\t\t\tsource.getFactory().getMappingMetamodel()\n\t\t\t\t\t\t\t.getEntityDescriptor( lazyInitializer.getEntityName() );\n\t\t\tfinal var key = source.generateEntityKey( id, persister );\n\t\t\tfinal var holder = persistenceContext.detachEntity( key );\n\t\t\t// if the entity has been evicted then its holder is null\n\t\t\tif ( holder != null && !lazyInitializer.isUninitialized() ) {\n\t\t\t\tfinal Object entity = holder.getEntity();\n\t\t\t\tif ( entity != null ) {\n\t\t\t\t\tfinal var entry = persistenceContext.removeEntry( entity );\n\t\t\t\t\tdoEvict( entity, key, entry.getPersister(), event.getSession() );\n\t\t\t\t}\n\t\t\t}\n\t\t\tlazyInitializer.unsetSession();\n\t\t}\n\t\telse {\n\t\t\tfinal var entry = persistenceContext.getEntry( object );","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultEvictEventListener.java#L33-L69","documentation":"Error \"Could not determine identifier of proxy passed to evict()\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when evict() is called with a lazy proxy whose identifier cannot be determined.","commonSituations":"Typical situations: evicting an uninitialized proxy whose id was never assigned; a proxy created with a null id.","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."],"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"}