I have started learning about Hibernate Second level cache.
I tried with the following sample code for understanding Hibernate second level cache.
Session session = sessionFactory.openSession();
session.beginTransaction();
UserDetails u1 = (UserDetails) session.get(UserDetails.class,1);
session.getTransaction().commit();
session.close();
Session session2=sessionFactory.openSession();
session2.beginTransaction();
UserDetails u2 = (UserDetails) session2.get(UserDetails.class, 1);
session2.getTransaction().commit();
System.out.println(u1==u2);
session2.close();
I am reading the same UserDetails object(with '1' as id) in 2 different sessions. It should return the same object as i have enabled second level cache.
But when i compare both the objects,its showing 'false'.
Can some one let me know how hibernate second level cache works internally?