Which is the Best Java Web Framework ?

Hibernate - Interview Questions and Answers on Cache

Q1.  Difference between first level and second level cache in hibernate ?

Ans. 

1. First level cache is enabled by default whereas Second level cache needs to be enabled explicitly.

2. First level Cache came with Hibernate 1.0 whereas Second level cache came with Hibernate 3.0.

3. First level Cache is Session specific whereas Second level cache is shared by sessions that is why First level cache is considered local and second level cache is considered global.

Q2.  What are the the methods to clear cache in Hibernate ?

Ans. Evict() and clear(). Evist is used to clear a particular object from the cache whereas clear clears the complete local cache.

Q3.  Name some second level cache types ?

Ans. 

1. EHCache ( Easy Hibernate )
2. OSCache  ( Open Symphony )
3. Swarm Cache ( JBoss )
4. Tree Cache ( JBoss )

Q4.  Can we disable first level cache ? What should one do if we don't want an object to be cached ?

Ans. No, We can either call evict after the object retrieval or can use separate sessions.  

Q5.  How to configure second level cache in Hibernate ?

Ans. 

1. Configure Provider class in Hibernate configuration file.

2. Add Cache usage tag ( read-only or read-write ) in mapping files ( hbm ).

3. Create an XML file called ehcache.xml and place in classpath which contains time settings and update settings, behavior of cache , lifetime and idletime of Pojos, how many objects are allowed.
Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
comments powered by Disqus




×

Try our new Java Interview Questions Search Tool.

There are more than 1000 questions with practice tests.

It's updated daily and It's Awesome.


×

Try our new Java Practice Test tool.

There are more than 200 questions and expanding quickly. It's updated daily and It's Awesome.