Hibernate executed queries and testing

痴心易碎 提交于 2019-12-24 16:16:27

问题


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.


回答1:


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

  • Hibernate Core Reference Guide
    • 3.4.6. Hibernate statistics
    • 20.6. Monitoring performance



回答2:


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

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



来源:https://stackoverflow.com/questions/3818070/hibernate-executed-queries-and-testing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!