Hibernate / Hibernate Caching
1. Explain hibernate caching.
Caching optimizes the application performance and it lies between the application and the database to minimize the number of database calls as many as possible to provide better performance for performance critical applications.
2. What are the different caching techniques in hibernate?
Hibernate provides three type of cache. First level cache : First level cache is associated with session object in hibernate and hibernate uses it by default....
3. Explain second level cache in hibernate.
Second level cache is on SessionFactory level. All the second level cache provider class must implement org.hibernate.cache.spi.CacheProvider by configuring the property hibernate.cache.provider_class.
4. What are the Caching implementations in Hibernate?
Hibernate supports four open-source cache implementations. EHCache (Easy Hibernate Cache), OSCache (Open Symphony Cache), Swarm Cache, and JBoss Tree Cache.
5. Advantages of EHCache (Easy Hibernate cache).
The below are the advantages of EHCache. (org.hibernate.cache.EhCacheProvider) It is fast.
6. Advantages of OSCache (Open Symphony Cache) in hibernate.
The below are the advantages of OSCache. (org.hibernate.cache.OSCacheProvider) It is powerful .
7. Explain about SwarmCache in Hibernate.
SwarmCache (org.hibernate.cache.SwarmCacheProvider) is a cluster-based caching. supports read-only or nonstrict read/write caching.
8. Explain about JBoss TreeCache in Hibernate.
JBoss TreeCache (org.hibernate.cache.TreeCacheProvider) is a powerful replicated and transactional cache which is useful when we need a true transaction-capable caching architecture .
9. Explain shared cache mode in second level cache of Hibernate.
To configure shared cache mode, hibernate provides javax.persistence.sharedCache.mode and it allows four values. ENABLE_SELECTIVE : Entities will not be cached until entity will be annotated by cacheable.
10. What are the different CacheMode in second level cache of hibernate?
There are 4 different CacheMode. CacheMode.NORMAL : This mode allows to read and write data in second level cache....
11. Explain query cache and It's configuration in hibernate.
Hibernate can cache query results. When a query is fetched frequently then caching query result is useful....
12. Explain the different cache concurrency strategy of second level cache in hibernate.
In hibernate, cache concurrency strategy can be set globally using the property hibernate.cache. default_cache_concurrency_strategy.
13. How do I enable Second level Cache using hibernate annotation?
In hibernate first level cache is provided by default. Hibernate do that by session....
14. What does hibernate.cache.use_structured_entries perform in hibernate?
This entry forces Hibernate to store data in the second-level cache (L2 cache) in a more human-friendly format.
15. How second level cache works in Hibernate?
Whenever hibernate session try to load an entity, it first looks for cached copy of entity in first level cache (associated with particular hibernate session).If cached copy of entity is present in first level cache, it is returned as result...
16. Can we disable first level cache in Hibernate?
Hibernate first level cache is enabled by default and there is no way to disable it. However hibernate provides methods using which selected objects can be deleted from the cache or clear the cache completely.
17. Explain evict method in Hibernate.
session.evict(obj) will remove the object instance from the session cache. Therefore if you are saving the object for the first time, you will have to explicitly commit via session.save(obj) before evicting the object from the cache....
18. Difference Between session.evict vs clear in Hibernate.
evict() evicts a single object from the session. clear() evicts all the objects in the session.
19. How do you find if an particular object exists at session cache?
We can use session contains() method to check if an object is present in the hibernate cache or not, if the object is found in cache, it returns true or else it returns false.
20. Role of eternal and maxElementsInMemory in ehcache.
eternal attribute maintains the data freshness and if true it indicates that mappings never expire. maxElementsInMemory is a count based capacity control that limits the cache size so that you do not exhaust memory of your application by filling up...
21. How to disable hibernate second level cache?
Hibernate second level cache can be disabled by, setting use_second_level_cache as false , using CACHEMODE.IGNORE , Using cache provider as org.hibernate.cache.NoCacheProvider.
22. Difference between time to live and time to idle in Ehcache.
timeToIdleSeconds enables cached object to be invalidated if it has not been requested for specified ('timeToIdleSeconds' ) seconds. timeToLiveSeconds enables cached object to be invalidated after that many seconds regardless of how many times or when cache was requested last...
23. Different Cache concurrency strategies in Hibernate.
read-only, nonstrict read-write, read-write, and transactional.
24. Explain collection cache in Hibernate.
Second Level Cache caches entities. Also, the second level cache also allows users to cache entity relationship information....
25. Effect of native query on hibernate cache.
When using native SQL queries you have to address the risk of invalidating existing cache when query cache enabled. Using SQLQuery, Hibernate couldn't know what cache regions you might affect, however you can explicitly provide the instruction....