Google News
logo
Java Hibernates - Interview Questions
How to enable second-level cache in hibernate?
To enable second-level cache we need to follow some points regarding cache, First level cache enabled by default. Whenever we are loading any object from the database, Then hibernate verify whether that object is available in the local cache memory of that particular session, means first level cache, if not available then hibernate verify whether the object is available in global cache or factory cache second-level cache, if not available then hibernate will hit the database and loads the object from there, and then first stores in the local cache of the session, the first level then in the global cache second-level cache.
 
Ex :
Session s2=sf.openSession();
s2.beginTransaction();
a=(user)s2.get(user.class,102);
System.out.println(a);
s2.getTransaction().commit();
s2.close();
Advertisement