jt_1000 wrote:
here is the quick cliff-notes to 2nd level cache...
1) you must setup a cache-provider in your hibernate.properties - choose ehCache.
2) you must specify what you want to cache - The two things that you can cache directly in the 2nd level are: Objects and Collections - if you cache objects, then basically it is an index by it's ID (either by <id> tag or by the hashCode method on your java class, if provided) into a table of objects - the values of the object are cached and ready to be retrieved. Here's the rub, you can only get to them by sess.LOAD, sess.GET or navigation to the object, that means you must know it's ID or use a fetch= 'select' strategy instead of "join" in your mapping relations. If you cache collections, then just the ID's are cached in the collection for that parent object. You'd need to specify the child's class to be cachable too <cache...>.
3) setup your session to use the 2nd level cache with session.setCacheMode(CacheMode.Normal) - ie, read and write to cache through your session.
4) Query cache works hand-in-hand with the 2nd level cache, in other words, if you issue a Query like Query q=sess.createQuery("from category"), and you setup the query to be cacheable, with q.setCacheable(true), then your query will be cached - if you issue the >>same<< query again, it won't hit the database even on new sessions... This is ideal for read-only data (like reference data) that doesn't ever change.
I hope that helps to get a fundamental understanding of it, and get you on your way...
Wow jt_1000, thank you very much for the fundamental breakdown of the cache and how to implement.
Thanks for taking the time again!
Timothy Grant Vogelsang