InterviewSolution
| 1. |
Explain Caching in Hibernate? |
|
Answer» Hibernate caching improves the PERFORMANCE of the application by pooling the object in the cache. It is useful when we have to fetch the same data multiple times. There are mainly two types of caching: first level cache and SECOND level cache.
This cache is associated with the session object and is enabled by default. It cannot be disabled. The first level cache data is not available to entire application. Hibernate provides methods which can be used to flush the cache or delete specific objects from the cache. Cached objects are not visible to the other sessions in the application and when the session is closed, all the cache objects are removed from MEMORY. The session evict() method is used to remove an object from the cache. The session clear() method clears the cache entirely. The session contains() method is used to CHECK if an object exists in the cache. It returns true if the object exists and false if it does not.
SessionFactory object HOLDS the second level cache data. The data stored in the second level cache will be available to entire application. But we need to enable it explicitly. |
|