How to Enable Hibernate Statistics to Analyze Performance

In Java world most of the developer have use Hibernate as ORM Framework in their applications development and most of them have encountering the performance issues. The beauty is most of the time performance issues are visible when application push to production.

According to my experience most of the performance drops are often related to slow database query at that time we need to find which queries causes the problem ? 😟

Don’t worry there is a easy way to find that issue. In hibernate can be configure to collect statistics and provide statistics to analyze database query issues.

Let’s see how we can do it.

Step 1. Enable hibernate.generate_statistics

properties.put(“hibernate.generate_statistics”, true);

state enable

Step 2. Hibernate Logs enable and set level to debug (This is not required)

logconfig

After these two steps you can run your code and refer the console logs for access the hibernate session statics. In there I’m used sample application for save 3 employee object and retrieve all employee from database.

app

Step 3. Access logs to read hibernate statics details.

console

Summary

In java applications to find performance issues, we can use hibernate statistics this configuration we can use development stage to identify the hibernate performance issue. Based on that we can
easily identify the application issues in which sections.

Hope this article helps to identify your application hibernate performance issue.