For the 2nd-level cache, you can use the Statistics API. See SessionFactory.getStatistics(), Statistics.getSecondLevelCacheStatistics(), and the SecondLevelCacheStatistics class in the Javadocs for specific details. Also note that you'll have to turn on generation of statistics via a property setting on the session factory. See section 3.4.6 of the hibernate manual.
A word of warning - the Statistics API has bugs of the NPE/CCE variety. I wouldn't put any code that accesses the API into production without being very careful. For example, there's a ClassCastException that occurs when you've got a cached query result in the 2nd-level cache and you try to access it.
_________________ - Matt
|