Friday, May 1, 2009

Hibernate Statistics

This is pretty cool. When you're experimenting with different mapping strategies, you can get Hibernate to provide you with stats for the number of queries, fetches, cache hits, and all manner of other operations.
So, just write a unit test that excercises the code you want to optimise, set stats on beforehand and dump them out afterwards. Then try a few different strategies and see which one gives you the right combination of numbers. It's not a substitute for a proper performance test harness and a profiler, but it looks like an invaluable tool for diagnosing problems.

Hibernate 3 also ships with a complete statistics and metrics API that allows you to figure out *everything* that is happening under the covers. All you have to do is a.) enable staticstics for the session factory and b.) retrieve the statistics and use them. Getting them an enabling them is easy:
SessionFactory sessionFactory = getSessionFactoryForApplication();
Statistics stats = sessionFactory.getStatistics();
stats.setStatisticsEnabled(true);

The tricky part (or at least the part that requires the most attention) is figuring out what statistics are available, and what they really mean. There are a billion methods available on the top level, but here is a glimpse (note, all of these values are based off of when statistics were enabled):
For more info read post on below link : http://www.javalobby.org/java/forums/t19807.html

Cheers!!!

Ujjwal B Soni

No comments: