1

Is there a way to find out what queries are executed with hibernate?

I would like to write a performance test to ensure only a specific query and amount are run.

Update: Just a clarification, i would like to programatically find out how many queries are run, not just via visual-manual inspection, so it would easily testable.

DataNucleus
  • 15,497
  • 3
  • 32
  • 37
JavaRocky
  • 19,203
  • 31
  • 89
  • 110

2 Answers2

3

Enable Hibernate statistics and use SessionFactory#getStatistics() to retrieve a Statistics and access the metrics related to queries.

See getQueries(), getQueryStatistics(String), QueryStatistics and the other methods.

References

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
0

hibernate.show_sql =true would show all the sqls executed.

http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html

frictionlesspulley
  • 11,070
  • 14
  • 66
  • 115