Multiple choice technology programming languages

What does session.evict() method do ?

  1. Remove the object and its collections from the first level cache

  2. Remove the object and its collections from the second level cache

  3. Remove the object and its collections from the data base

  4. None of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

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.

AI explanation

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.