tags:

views:

537

answers:

1

As far as I know Hibernate let's you configure entities and collections to be stored in a second-level cache.

When does Hibernate try to read these cached entities from the second-level cache and when does it hit the DB? Does Hibernate only read from the second-level cache when loading entities by calling Sesssion.get() and when initializing proxies (including collections)? Does Hibernate ever hit the second-level cache when executing HQL- or Criteria-Queries?

Examples?

+2  A: 

(Note: the easiest way to answer that type of questions is to turn show_sql on and see what queries Hib generates.)

Sometimes query only return PKs of the records (e.g. for iteration queries) and then Hib can use the cache.

When retrieving linked objects cache can be used too.

I cannot though give you the precise rule here. I also suspect the answer depends on capabilities of dialect used.

Vladimir Dyuzhev