views:

261

answers:

1

I've configure a few of my objects to be cacheable ( on the mapping file) and from what I can see for this particular object the cache is not working so well.

For other objects I see the hit count increasing on each iteration, but the missed count as 0, whereas for this one I see it misses every single time for the session.

Elements in Memory: 8305 
Elements on Disk: 0 
Hit Count: 24915 
Missed Count 8305 
Put Count: 8305

I am looking for some pointers to what might be wrong.

  • As background I've checked equals and hashCode implementations, and even debugging seems to be returning the correct results.
  • This particular object is used in collections for other objects, as well as a top level one.
+2  A: 

Surely those stats show that you are hitting the cache correctly.

If you are getting an object my it's id, hibernate will follow roughly the following steps:

  1. check in the first level cache (Session object)
  2. check the second level cache, and miss
  3. load the object from the db
  4. put in the second level cache for next time

The most likely explanation for the other objects not registering a miss is that you are not accessing them by there id, rather you using a query or some association whether a direct cache access is not possible.

Gareth Davis