I have a pretty standard persistence layer setup in my Spring driven application using Hibernate (4.2.15.Final) with EhCache (2.6.9) as 2nd level cache.
Everything w
Short answer
Turns out that the problem I'm having is a result of using Joda-Time instances in my model (I'm using Jadira's UserType library to map Joda types).
Joda types keep all sorts of internal references (including references to chronology information resulting in a huge object graph) and Ehcache's SizeOfEngine
walks these references leading to my original warning.
I found no clean way how to configure the SizeOfEngine engine to exclude these references, but then again I guess a cleaner approach would be to force Hibernate to only put the relevant info into the 2nd level cache in the first place (a time instance in my case of LocalDateTimes
).
Update
Jadira took a poor choice when implementing its custom types: See my answer here
More Details
Here's what I found regarding my OP (using Hibernate 4.2.15.Final, EhCache 2.6.9 and UserType 3.2.0.GA):
First of all, I had a misconception about how Hibernate stores entities in it's 2nd-Level cache. After reading Lorimer's blog entry about Truly Understanding the Second-Level and Query Caches a lot of things made more sense to me:
maxBytesLocalHeap
configuration. Currently problems arise when you use custom user types which are not measured correctly by EhCache's SizeOf engine.I know that it is an old question. But it might be useful for somebody. I've got the same warning. I spent a lot of time to solve this issue. In my case EhCache doesn't ignore all hibernate proxy classes. My entity have some fields with lazy association and during sizeof measurement EhCache walk through whole hibernate graph.
Finally I found this page and solve it.