问题描述
有没有一种方法可以找出休眠状态下执行的查询?
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.
推荐答案
启用Hibernate统计信息并使用 SessionFactory#getStatistics()
来检索 Statistics
并访问与查询相关的指标.
Enable Hibernate statistics and use SessionFactory#getStatistics()
to retrieve a Statistics
and access the metrics related to queries.
请参见 getQueries()
, getQueryStatistics(String)
, QueryStatistics
和其他方法.
See getQueries()
, getQueryStatistics(String)
, QueryStatistics
and the other methods.
- Hibernate Core参考指南
- Hibernate Core Reference Guide
- 3.4.6. Hibernate statistics
- 20.6. Monitoring performance
这篇关于休眠执行的查询和测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
- Hibernate Core Reference Guide