First level cache

In the first level cache, Hibernate caches entities in session objects. The Hibernate first level cache is enabled by default, and we cannot disable it. Still, Hibernate provides methods through which we can delete particular objects from the cache, or completely clear the cache from a session object.

As Hibernate does a first level cache in a session object, any object cached will not be visible to another session. When the session is closed, the cache is cleared. We are not going to go into detail on this caching mechanism, as it is available by default, and there is no way to tune or disable it. There are certain methods to know for this level of cache, as follows:

  • Use the session's evict() method to delete a single object from the Hibernate first level cache
  • Use the session's clear() method to clear the cache completely
  • Use the session's contains() method to check whether an object is present in the Hibernate cache
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset