在我的MySQL上查看SHOW GLOBAL STATUS
时,会发现Com_select
和Com_show_warnings
或多或少相等。这意味着Hibernate为它执行的每个查询执行SHOW WARNINGS
。有没有办法禁用它?谷歌没有帮助:/
如本文所述,当我们从warn
或更高级别设置日志级别时,hibernate会强制我们使用SHOW WARNINGS
。
这是代码的一部分:
public void handleAndClearWarnings(
Connection connection,
WarningHandler handler) {
try {
/* This is the real method that causing the problem. */
walkWarnings( connection.getWarnings(), handler );
}
catch (SQLException sqle) {
// workaround for WebLogic
LOG.debug( "could not log warnings", sqle );
}
try {
// Sybase fail if we don't do that, sigh...
connection.clearWarnings();
}
catch (SQLException sqle) {
LOG.debug( "could not clear warnings", sqle );
}
}
因此,为了避免walkWarnings()
方法被执行,您可以尝试将log4j.logger.org.hibernate
级别更改为error
。