I am new to Hibernate and have a question regarding the 2nd-level cache feature.
Environment: Hibernate 3.2CR2 with SQL Server 2005
I have a simple persistent class named Event, and I have enabled caching for it. Here is a code fragment that illustrates a load, followed by an update, then another load:
Code:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Event anEvent = (Event) session.load(Event.class, new Long(1));
System.out.println(anEvent.getTitle());
anEvent.setTitle(anEvent.getTitle() + "*");
session.getTransaction().commit();
session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
anEvent = (Event) session.load(Event.class, new Long(1));
System.out.println(anEvent.getTitle());
session.getTransaction().commit();
Using the org.hibernate.cache.HashtableCacheProvider cache provider, if I specify a cache strategy "nonstrict read/write", the second load issues a second SELECT (cache is not used). But if I use the cache strategy "read/write", the second load appears to retrieve the object from cache (the desirable behavior).
Can someone explain the difference between the two strategies, and why I am observing the behavior I see? I have found a couple of other posts about this, but none comparing these two strategies.
Thanks in advance!