Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Caching in Hibernate: Second Level Cache

Second Level cache: Second Level Cache can be attached to Session Factory.


Objects which are stored in second level cache can be shared with all the sessions.
For eg:

         Session session1=sessionFactory.openSession();
         session1.get(Project.class,1);      //fetch project object with primary key 1,from database.
         session.close();

         session2=sessionFactory.openSession();
         session2.get(Project.class,1);     // Again fetch the project objec (pk 1) from database not from cache.
         session.close();
         


This post first appeared on Java Spring Hibernate, please read the originial post: here

Share the post

Caching in Hibernate: Second Level Cache

×

Subscribe to Java Spring Hibernate

Get updates delivered right to your inbox!

Thank you for your subscription

×