休眠执行的查询和测试 [英] Hibernate executed queries and testing

查看:103
本文介绍了休眠执行的查询和测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以找出休眠状态下执行的查询?

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统计信息并使用

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

请参见 getQueries() getQueryStatistics(String)

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆