Steven Henry
Steven Henry

Reputation: 101

How to monitor each query execution time with hibernate?

In hibernate,I'm using show_sql property=true and as well hibernate.generate_statistics=true .But this doesnt helped me lot. Awaiting for the suggestions and thanks in advance.

Upvotes: 3

Views: 7919

Answers (4)

Ravi Surthi
Ravi Surthi

Reputation: 51

You can also use Library datasource-proxy. Which will log the exact SQL query with appended parameters and execution time as well. This will help you better I guess.

Upvotes: 3

Ravi Surthi
Ravi Surthi

Reputation: 51

First step sperate Query building and query execution in two methods. And then apply @Loggable annotation on execution method. You can read the details of it here. Which will print the amount of time taken by method execution.

Upvotes: 0

Jonck van der Kogel
Jonck van der Kogel

Reputation: 3293

Have a look at the JConsole Hibernate plugin: http://hibernate-jcons.sourceforge.net/usage.html

Using this you will be able to see all the queries being performed as well as running times.

Upvotes: 0

Vikas Sharma
Vikas Sharma

Reputation: 755

Do these steps :-

Change the log4j's level to trace on org.hibernate.stat

logging on the package: org.hibernate.stat at least on INFO and

set hibernate property: hibernate.generate_statistics=true

Afterwards all the SQLs will be logged and the time the query execution took.

It provides statistics on queries. If you want you can expose them via JMX and see them using JConsole (http://hibernate-jcons.sourceforge.net/).

Upvotes: 2

Related Questions