Anders, this link is a pretty good explanation of the 2nd level cache:
http://www.javalobby.org/java/forums/t48846.html
Quote:
I get a list of objects from the DB with hibernatetemplate.loadAll this list is saved in the 2nd-lvl-cache (as strings references by the id, am i correct?).
All results will be individually cached if a cache region is configured for the resulting class.
Quote:
Then i do exactly the same thing again, at first i would think that this caused hibernate to get the entire list from the cache. (does it) ?
No, this won't look in the cache. Behind the scenes, the HibernateTemplate builds a query to return all data. Query results ALWAYS come from the db unless the query is cached.
Quote:
presuming that the 2nd list does come from the cache, why does hibernate refresh the changed object before it's time to live has run out?
It doesn't, for reasons mentioned above.
Quote:
until now i haven't used query cache, what impact on my lists would this have? if any at all?
I don't think you can use the query cache with hibernateTemplate.loadAll(), but you can just as easily build your own criteria to return all data and set cachable to true.
Quote:
if i changed my loadall method to some query like ("from sometable") i should get the same list of object, but would this get med the list from the cache the 2nd time?
Yes! As long as you have configured the query to be cachable.
-Paul