{"record":{"id":"b1826bdeb6fb5870","repo":"hibernate/hibernate-orm","slug":"non-entity-object-instance-passed-to-evict-obje","errorCode":null,"errorMessage":"Non-entity object instance passed to evict: ${object}","messagePattern":"Non-entity object instance passed to evict: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/event/internal/DefaultEvictEventListener.java","lineNumber":98,"sourceCode":"\t * Make sure the passed object is even an entity, and if not throw an exception.\n\t * This is different to the legacy Hibernate behavior, but is what JPA 2.1\n\t * requires with EntityManager.detach().\n\t */\n\tprivate static void checkEntity(@Nonnull Object object, @Nonnull EventSource source) {\n\t\tfinal String entityName = source.getSession().guessEntityName( object );\n\t\tif ( entityName != null ) {\n\t\t\ttry {\n\t\t\t\tfinal var persister =\n\t\t\t\t\t\tsource.getFactory().getMappingMetamodel()\n\t\t\t\t\t\t\t\t.getEntityDescriptor( entityName );\n\t\t\t\tif ( persister != null ) {\n\t\t\t\t\treturn; //ALL GOOD\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (Exception ignore) {\n\t\t\t}\n\t\t}\n\t\tthrow new IllegalArgumentException( \"Non-entity object instance passed to evict: \" + object);\n\t}\n\n\tprotected void doEvict(\n\t\t\t@Nonnull final Object object,\n\t\t\t@Nonnull final EntityKey key,\n\t\t\t@Nonnull final EntityPersister persister,\n\t\t\t@Nonnull final EventSource session)\n\t\t\tthrows HibernateException {\n\t\tif ( EVENT_LISTENER_LOGGER.isTraceEnabled() ) {\n\t\t\tEVENT_LISTENER_LOGGER.evicting( infoString( persister ) );\n\t\t}\n\n\t\tfinal var persistenceContext = session.getPersistenceContextInternal();\n\t\tif ( persister.hasNaturalIdentifier() ) {\n\t\t\tpersistenceContext.getNaturalIdResolutions().handleEviction( key.getIdentifier(), object, persister );\n\t\t}\n\n\t\t// remove all collections for the entity from the session-level cache","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultEvictEventListener.java#L80-L116","documentation":"Error \"Non-entity object instance passed to evict: ${object}\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when evict() receives an object that is neither a managed entity nor an entity proxy.","commonSituations":"Typical situations: passing a DTO, embeddable, or plain object to Session.evict(); a variable holding the wrong object.","solutions":["Pass only mapped entity instances to Session.evict(); verify the object's class is annotated with @Entity or mapped in configuration.","If the object is a DTO or value type, remove the evict() call since only managed entities belong to the persistence context."],"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"}