What does session.evict() method do ?
-
Remove the object and its collections from the first level cache
-
Remove the object and its collections from the second level cache
-
Remove the object and its collections from the data base
-
None of the above
The session.evict() method removes an object and its associated collections from the first-level cache (session cache). This detaches the object from the session, meaning subsequent changes won't be tracked. It does not affect the second-level cache or delete from the database.
In Hibernate, Session.evict(object) removes a specific persistent instance and its collections from the first-level (session-scoped) cache, detaching it so subsequent changes to it won't be tracked or flushed to the database automatically. It does not touch the second-level cache (which requires SessionFactory.evict or the second-level cache provider's own APIs) and it certainly doesn't delete data from the actual database — that would require an explicit delete() call. So 'first level cache' is the precise, correct scope.