问题描述
我已经设置了
<property name="show_sql">false</property>
并且我已禁用 log4j.properties 中的所有消息
and I have disabled all messages in log4j.properties
但是 Hibernate 将所有查询写入控制台声明.
But Hibernate write to console with all queries & statements.
推荐答案
将 hibernate.show_sql
设置为 true
告诉 hibernate 将所有 SQL 语句写入控制台.这是将日志类别 org.hibernate.SQL
设置为调试的替代方法.
Setting the hibernate.show_sql
to true
tells hibernate to Write all SQL statements to console. This is an alternative to setting the log category org.hibernate.SQL
to debug.
因此,即使您将此属性设置为 false
,请确保您没有定义以下类别(或配置为使用控制台附加程序):
So even if you set this property to false
, make sure that you don't have the following category defined (or configured to use a console appender):
log4j.logger.org.hibernate.SQL=DEBUG
此外,请确保在实例化 Configuration
对象时,不要以编程方式将 hibernate.show_sql
设置为 true.狩猎这样的东西:
Also, make sure that you don't set the hibernate.show_sql
programmatically to true when instancing your Configuration
object. Hunt something like this:
Configuration cfg = new Configuration().configure().
.setProperty("hibernate.show_sql", "true");
请注意,setProperty(String propertyName, String value)
将配置属性的全名作为第一个参数,即 hibernate.show_sql
,而不仅仅是 show_sql
.
Note that the setProperty(String propertyName, String value)
takes as first parameter the full name of a configuration property i.e. hibernate.show_sql
, not just show_sql
.
这篇关于无法阻止 Hibernate 将日志写入控制台(log4j.properties 可以)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!